测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2016 年 12 月 |
SwiftSwift版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Joe Fabisevich 维护。
介绍,GenericCells!… 利用 Swift 中的泛型,我们可以在不每个都创建新类的情况下,获得自定义 UITableViewCell 或 UICollectionViewCell 类的所有好处。
为所需的布局创建一个 UIView 子类
final class MyView: UIView {
let imageView: UIImageView
let titleLabel: UILabel
let subtitleLabel: UILabel
// And add more views to your heart's content
}
将单元格与 UITableView 或 UICollectionView 注册
tableView.register(GenericTableCell<MyView>.self)
collectionView.register(GenericCollectionCell<MyView>.self)
使用 UITableView 或 UICollectionView dequeuing 单元格
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as GenericTableCell<MyView>
let cell = collectionView.dequeueReusableCell(forIndexPath: indexPath) as GenericCollectionCell<MyView>
并按您的喜好进行自定义。您想要访问的视图将通过 .customView
属性可用
cell.customView.titleLabel.text = "This library rules!"
cell.customView.imageView.image = UIImage(named: "success")
加分项,让我们支持回收。通过对视图扩展 ReusableGenericView
协议
extension MyView: ReusableGenericView {
func prepareForReuse() {
self.titleLabel.text = ""
self.subtitleLabel.text = ""
self.imageView.image = nil
}
}
当单元格被回收时,它将被调用。
您可以使用 CocoaPods 通过将其添加到您的 Podfile
中来安装 GenericCells
platform :ios, '9.0'
use_frameworks!
pod 'GenericCells'
或手动安装,通过下载 GenericTableCell.swift
、GenericCollectionCell.swift
和 ReusableView.swift
并将其拖放到您的项目中。
嗨,我在网络上无处不在,尤其是在 Twitter 上。
有关如何使用 GenericCells 的更多信息,请参阅 许可证
是的,这就是全部。如果不满意,请原谅,这是一条彩虹。