IGListKit/Examples/Examples-iOS/IGListKitExamples/SectionControllers/StoryboardLabelSectionController.swift
Bofei Zhu 1d3e58b9fd Create a grid layout for IGList
Summary:
Rebase from #140:

Create a flow layout for IGList that does not newline sections. Closes #3

- [x] Minimum inter-item spacing
- [x] Minimum line spacing
- [x] Constant item size with constant layout time
- [x] Update layout on insert/delete/move
- [x] Unit Test
Closes https://github.com/Instagram/IGListKit/pull/225

Differential Revision: D4211469

Pulled By: rnystrom

fbshipit-source-id: f4710dbf195701098ac50f94b6b2aa8c801b2a83
2016-11-21 13:29:04 -08:00

49 lines
1.7 KiB
Swift

/**
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
The examples provided by Facebook are for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import UIKit
import IGListKit
protocol StoryboardLabelSectionControllerDelegate: class {
func removeSectionControllerWantsRemoved(_ sectionController: StoryboardLabelSectionController)
}
final class StoryboardLabelSectionController: IGListSectionController, IGListSectionType {
var object: Person?
weak var delegate: StoryboardLabelSectionControllerDelegate?
func numberOfItems() -> Int {
return 1
}
func sizeForItem(at index: Int) -> CGSize {
return CGSize(width: (self.object?.name.characters.count)! * 7, height: (self.object?.name.characters.count)! * 7)
}
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCellFromStoryboard(withIdentifier: "cell", for: self, at: index) as! StoryboardCell
cell.textLabel.text = object?.name
return cell
}
func didUpdate(to object: Any) {
self.object = object as? Person
}
func didSelectItem(at index: Int) {
delegate?.removeSectionControllerWantsRemoved(self)
}
}