IrregularCollectionUIKit 2.0.1

IrregularCollectionUIKit 2.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2017

Maintained by pisces.



  • By
  • Steve Kim







Example

To run the example project, clone the repo, and run pod install from the Example directory first.

You can implement layout of collection view like this screenshot :)

Implementation for collection view with the class IrregularCollectionViewController using UIKit

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))
    }
}

Implementation for collection view with 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)

Requirements

iOS Deployment Target 7.0 higher

Installation

IrregularCollectionUIKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "IrregularCollectionUIKit"

Author

Steve Kim, [email protected]

License

IrregularCollectionUIKit is available under the MIT license. See the LICENSE file for more info.