import UIKit
import SectionKit
class SpacerCell: UICollectionViewCell, SKConfigurableView, SKLoadViewProtocol {
public struct Model {
public let size: CGSize
public let backgroundColor: UIColor?
}
public func config(_ model: Model) {
self.backgroundColor = model.backgroundColor
}
public static func preferredSize(limit size: CGSize, model: Model?) -> CGSize {
guard let model = model else {
return .zero
}
return model.size
}
}
let model = FLSpacerCell.Model(size: .zero)
/// 以下 API 完全等价
let section1 = FLSpacerCell.wrapperToSingleTypeSection([model])
let section2 = FLSpacerCell.wrapperToSingleTypeSection(model)
let section3 = SKCSingleTypeSection<FLSpacerCell>([model])
let section4 = SKCSingleTypeSection<FLSpacerCell>(model)
与 UICollectionView 关联
/// 创建 Section
let model = FLSpacerCell.Model(size: .zero)
let section1 = FLSpacerCell.wrapperToSingleTypeSection([model])
let section2 = FLCustomCell.wrapperToSingleTypeSection(model)
/// manager 与 UICollectionView 关联
let sectionView = UICollectionView(frame: .zero,collectionViewLayout: UICollectionViewFlowLayout())
let manager = SKCManager(sectionView: sectionView)
/// 加载 section1, section2
manager.reload([section1, section2])
let section = SKCRegistrationSection {
SupplementaryView
.registration((), for: .header)
/// 配置 supplementary 样式
.viewStyle({ view, model in })
.onWillDisplay { model in }
.onEndDisplaying { model in }
FLSpacerCell
.registration(model)
/// 配置 cell 样式
.viewStyle({ view, model in })
/// 响应 cell 选中事件
.onSelected { model in }
.onHighlight { model in }
.onWillDisplay { model in }
.onEndDisplaying { model in }
// ...
}
/// 配置 section 样式
.setSectionStyle { section in
section.minimumInteritemSpacing = 10
section.minimumLineSpacing = 10
section.sectionInset = .init(top: 10, left: 10, bottom: 10,right: 10)
}
SectionKit
前提条件:
安装
Cocoapods
Swift Packages URL
其他文档
创建通用型单元视图
UICollectionViewCell:
UICollectionReusableView:
SKCSingleTypeSection
创建 Section
与 UICollectionView 关联
样式配置
数据操作
事件订阅
SKCRegistrationSection
创建 Section
与 UICollectionView 关联
样式配置
数据操作
事件订阅
自定义 Section
创建 Section
与 UICollectionView 关联
数据操作
事件订阅