测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布日期最新版本发布日期 | 2016年10月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Dima Pilipenko 维护。
一个 Swift 库,它提供了通用的集合视图控制器,具有外部数据处理功能,例如确定与 indexPath
相关的 cell 的 reuseIdentifier
,配置用于显示的 cell 和 cell 选择处理器等
使用配置进行初始化
_flexibleCollectionVC = FlexibleCollectionViewController(collectionViewLayout: CustomFlowLayout(), configuration: CollectionConfiguration(userInteractionEnabled: true, showsHorizontalScrollIndicator: false, isScrollEnabled: true, multipleTouchEnabled: false, backgroundColor: .clear))
Cell 和补充视图注册
_flexibleCollectionVC.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "UICollectionViewCell")
_flexibleCollectionVC.registerSupplementaryView(UIHeaderImageCollectionView.self, kind: .header, reuseIdentifier: UIHeaderImageCollectionView.reuseIdentifier)
请求特定 indexPath
的 cell 的 identifier
_flexibleCollectionVC.requestCellIdentifier = { value in
return "UICollectionViewCell"
}
请求特定 indexPath
的补充视图的 identifier
_flexibleCollectionVC.requestSupplementaryIdentifier = { value in
return UIHeaderImageCollectionView.reuseIdentifier
}
使用与 indexPath
相关的数据配置输入 cell
_flexibleCollectionVC.configureCell = { (cell: UICollectionViewCell, data: CollectionImageCellData?, indexPath: IndexPath) in
guard let data = data else {
return false
}
cell.backgroundColor = data.color
return true
}
使用与 indexPath
相关的种类和数据配置补充视图
_flexibleCollectionVC.configureSupplementary = { (view: UICollectionReusableView, kind: SupplementaryKind, data: CollectionImageCellData?, indexPath: IndexPath) in
if let view = view as? UIHeaderImageCollectionView, let data = data {
view.text = data.category
return true
}
return false
}
处理 cell 选择与相关 indexPath
_flexibleCollectionVC.cellDidSelect = { value in
return (deselect: true, animate: true)
}
估算 cell 的大小
_flexibleCollectionVC.estimateCellSize = { value in
guard let layout = value.1 as? UICollectionViewFlowLayout else {
return nil
}
let col: CGFloat = 3
let width = value.0.bounds.width-(layout.sectionInset.left+layout.sectionInset.right)
let side = round(width/col)-layout.minimumInteritemSpacing
return CGSize(width: side, height: side)
}
将预定义的 cell 按照与 ListGenerator 相关的生成顺序放置
_flexibleCollectionVC.setData(getData())
Swift 3 或以上
FlexibleCollectionViewController 可通过 CocoaPods 获取。要安装,只需在 Podfile 中添加以下行
pod "FlexibleCollectionViewController"
Pilipenko Dima,[email protected]
FlexibleCollectionViewController 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。