IrregularCollectionUIKit 2.0.1

IrregularCollectionUIKit 2.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新版本2017年10月

pisces维护。



  • Steve Kim







示例

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

您可以像这样实现集合视图的布局:)

使用 UIKit 的 IrregularCollectionViewController 类实现的集合视图

class DemoViewController: IrregularCollectionViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        collectionViewLayout.columnSpacing = 1
        collectionViewLayout.numberOfColumns = 3
        collectionViewLayout.sectionInset = UIEdgeInsetsMake(1, 1, 1, 1)
        collectionView.register(SampleViewCell.self, forCellWithReuseIdentifier: "SampleViewCell")
    }
    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return contents.count
    }
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return collectionView.dequeueReusableCell(withReuseIdentifier: "SampleViewCell", for: indexPath)
    }
    override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        (cell as? SampleViewCell)?.content = contents[indexPath.item]
    }
    override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, originalItemSizeAt indexPath: IndexPath) -> CGSize {
        let content = contents[indexPath.item]
        return CGSize(width: CGFloat(content.width), height: CGFloat(content.height))
    }
}

使用 IrregularCollectionViewLayout 实现的集合视图

let layout = IrregularCollectionViewLayout()
layout.delegate = self
layout.columnSpacing = 1
layout.numberOfColumns = 3
layout.sectionInset = UIEdgeInsetsMake(1, 1, 1, 1)
        
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)

要求

iOS 部署目标 7.0 以上

安装

IrregularCollectionUIKit 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行:
CocoaPods

pod "IrregularCollectionUIKit"

作者

Steve Kim, [email protected]

许可证

IrregularCollectionUIKit 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。