CollectionManager 1.0.0

CollectionManager 1.0.0

jjfernandes87 维护。



CollectionManager

一个创建和操作 UICollectionView 的简单方式。

CI Status Version License Platform

功能

  • 通过仅传递一个数组来加载 UICollectionViewCell 集合
  • 为每个单元格加载不同边距的 UICollectionViewCell 集合
  • 加载 UICollectionViewCell,使用 xib 而不是实现 Register(nib)
  • 使用一行代码删除 UICollectionViewCell
  • 自定义 Your UICollectionViewCell 的大小

要求

  • iOS 11.0+
  • Xcode 10.1+
  • Swift 4.2+

沟通

  • 如果 发现 bug,请创建 issue。
  • 如果您 有新功能,请创建 issue。
  • 如果您 想贡献力量,请提交 pull request。

例子

为了运行示例项目,请首先克隆仓库,然后在Example目录下运行pod install命令。

安装

CollectionManager可通过CocoaPods访问。要安装,请只需在您的Podfile中添加以下行:

pod 'CollectionManager'

创建CellController和CellView。请注意,您需要为扩展CellController的类添加@objc,因为这需要我们的CollectionManager使用类名作为cellIdentifier(您必须将您的UICollectionViewCell配置为与CellController相同的名称,在您的Xib或Storyboard中)

import CollectionManager

@objc(CustomCell)
class CustomCell: CellController {
...
}

class CustomCellView: CellView {
...
}

创建您的CellController类后,现在需要实现运行所需的方法。

import CollectionManager

@objc(CustomCell)
class CustomCell: CellController {
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        ...
    }
    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        ...
    }
}

在我们的CellView类中,我们暴露我们的IBOutlets。

class CustomCellView: CellView {
    @IBOutlet weak var ...
}

现在只剩下一点!我们需要用我们刚刚构建的cell来填充我们的Interface。

import CollectionManager

class ViewController: UIViewController {

    @IBOutlet weak var collectionView: CollectionViewManager!

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.items = [CustomCell(),CustomCell(),CustomCell(),CustomCell(),CustomCell(),CustomCell()]
        //or
        collectionView.setSectionsAndItems = /* caso você tenha SectionController */
    }
}

完成了!

作者

jjfernandes87, [email protected]

许可

CollectionManager根据MIT许可提供。有关更多信息,请参阅LICENSE文件。