2016-11-16 16:01:27 +00:00
|
|
|
/**
|
|
|
|
|
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
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
final class CarouselSectionController: IGListSectionController {
|
2016-11-16 16:01:27 +00:00
|
|
|
|
|
|
|
|
var number: Int?
|
|
|
|
|
|
|
|
|
|
override init() {
|
|
|
|
|
super.init()
|
|
|
|
|
self.inset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
override func numberOfItems() -> Int {
|
2016-11-16 16:01:27 +00:00
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
override func sizeForItem(at index: Int) -> CGSize {
|
2016-11-16 16:01:27 +00:00
|
|
|
let height = collectionContext?.containerSize.height ?? 0
|
|
|
|
|
let aspectRatio: CGFloat = 0.75 // 3:4
|
|
|
|
|
let width = height * aspectRatio
|
|
|
|
|
|
|
|
|
|
return CGSize(width: width, height: height)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
2016-11-16 16:01:27 +00:00
|
|
|
let cell = collectionContext!.dequeueReusableCell(withNibName: "CarouselCell", bundle: nil, for: self, at: index) as! CarouselCell
|
|
|
|
|
let value = number ?? 0
|
|
|
|
|
cell.titleLabel.text = "#\(value + 1)"
|
|
|
|
|
return cell
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
override func didUpdate(to object: Any) {
|
2016-11-16 16:01:27 +00:00
|
|
|
number = object as? Int
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 23:10:37 +00:00
|
|
|
override func didSelectItem(at index: Int) {}
|
2016-11-16 16:01:27 +00:00
|
|
|
|
|
|
|
|
}
|