This project provide example how to implement multicolumn multilie layout for UICollectionView
- Swift 3, Xcode 8.2+, AutoLayout
- Minimum iOS version is 8.2
For Swift 2.3 see related branch
This is example project and you should not care most of the sources.
You only interested in DynamicHeightLayout.swift as layout implementation and in MainCVC.swift and NewsCell.swift as usage example.
-
Drop
DynamicHeightLayout.swiftinto your project -
Implement
DynamicHeightLayoutDelegate -
Set DynamicHeightLayout as custom layout class for your collection view controller in storyboard or from code
-
Provide delegate for
DynamicHeightLayoutoverride func viewDidLoad() { super.viewDidLoad() let layout = collectionViewLayout as! DynamicHeightLayout layout.delegate = self } -
Calculate height of each cell and return it when
DynamicHeightLayoutDelegatewill ask
Look at the MainCVC.swift for setup example
Example how to calculate height for cell with multilined labels in NewCell.swift
It should be fast, as soon as DynamicHeightLayout fill out its cache for UICollectionViewLayoutAttributes.

