GenericTableCell 1.0

GenericTableCell 1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2016 年 12 月
SwiftSwift版本3.0
SPM支持 SPM

Joe Fabisevich 维护。



GenericCells

创建 UITableViewCell 和 UICollectionViewCell 子类在 Swift 2.0 真的是如此简单。


介绍,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.swiftGenericCollectionCell.swiftReusableView.swift 并将其拖放到您的项目中。

关于我

嗨,我在网络上无处不在,尤其是在 Twitter 上。

许可证

有关如何使用 GenericCells 的更多信息,请参阅 许可证

这就是全部吗?

是的,这就是全部。如果不满意,请原谅,这是一条彩虹。🌈