ReusableProtocol 0.1.0

ReusableProtocol 0.1.0

Leo 维护。



ReusableProtocol

CI Status Version License Platform Laguage CocoaPods LeoDev GitHub stars

🎏ReusableProtocol 是一个实用的、纯 Swift 实现的库,用于注册和重用表格视图和收集视图中的单元格或视图。您可能从不在乎重用标识符是什么。

示例

要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install

要求

  • iOS 8.0+

安装

ReusableProtocol 可以通过 CocoaPods 获取。 要安装它,只需将以下行添加到您的 Podfile 中。

pod 'ReusableProtocol'

使用

  • 注册单元格或视图

    // UITableView
    tableView.register(TableViewCell.self)
    tableView.register(TableViewHeaderView.self)
    
    // UICollectionView
    collectionView.register(CollectionViewCell.self)
    collectionView.register(CollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader)
  • 出队单元格或视图

    // UITableView
    let cell = tableView.dequeueReusableCell(with: TableViewCell.self, for: indexPath)
    let view = tableView.dequeueReusableHeaderFooterView(with: TableViewHeaderView.self)
    
    // UICollectionView
    let cell = collectionView.dequeueReusableCell(with: CollectionViewCell.self, for: indexPath)
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, viewClass: CollectionHeaderView.self, for: indexPath)
  • 可选:您可能希望从nib中注册单元格或视图。

    // UITableView
    tableView.register(TableViewCell.self, fromNib: true)
    tableView.register(TableViewHeaderView.self, fromNib: true)
    
    // UICollectionView
    collectionView.register(CollectionViewCell.self, fromNib: true)
    collectionView.register(CollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, fromNib: true)

作者

Leo, [email protected]

许可证

ReusableProtocol遵从MIT许可证。更多信息请参阅LICENSE文件。