Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension CollectionView: CHTCollectionViewDelegateWaterfallLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemWidth = itemsArray[indexPath.row].width
let itemHeight = itemsArray[indexPath.row].height
return CGSize(width: itemWidth, height: itemHeight)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, columnCountFor section: Int) -> Int {
return 2
}
}
override func viewDidLoad() {
super.viewDidLoad()
//Other...
// CollectionView Layout Setup
setupCollectionViewLayout()
}
func setupCollectionViewLayout() {
// Create a waterfall layout
let layout = CHTCollectionViewWaterfallLayout()
// Change individual layout attributes for the spacing between cells
layout.minimumColumnSpacing = 3.0
layout.minimumInteritemSpacing = 3.0
// Set the waterfall layout to your collection view
self.collectionView.collectionViewLayout = layout
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.