- Supports Headers and Footers
- Highly Customizable
- Change the number of columns
- swift 5
To run the example project, clone the repo, and run pod install
from the Example directory first.
PinterestUISwift is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PinterestUISwift'
import PinterestUISwift
class ViewController: UIViewController, collectionViewFlowDataSource{
// MARK: Variables
var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let layout = collectionViewLayout(delegate: self)
if #available(iOS 10.0, *) {
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
} else {
// Fallback on earlier versions
}
collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height:self.view.frame.height), collectionViewLayout: layout)
collectionView.backgroundColor = .white
collectionView.dataSource = self
collectionView.delegate = self
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
view.addSubview(collectionView)
collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")
let nib:UINib = UINib(nibName: "Header", bundle: nil)
collectionView.register(nib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "Header")
}
}
func sizeOfItemAtIndexPath(at indexPath: IndexPath) -> CGFloat {
// take image height and return the height
let height = Float.random(in: 80 ..< 400)
return CGFloat(height)
}
func numberOfCols(at section: Int) -> Int {
return 2
}
func spaceOfCells(at section: Int) -> CGFloat{
return 12
}
func sectionInsets(at section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 10, left: 10, bottom: 50, right: 10)
}
func sizeOfHeader(at section: Int) -> CGSize{
return CGSize(width: view.frame.width, height: 150)
}
func heightOfAdditionalContent(at indexPath : IndexPath) -> CGFloat{
return 0
}
Faris Albalawi, developer.faris@gmail.com
PinterestUISwift is available under the MIT license. See the LICENSE file for more info.