Just two steps with Auto Layout
:
1.
flowLayout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
2.set up constraints for your cells
References:
- https://medium.com/@wasinwiwongsak/uicollectionview-with-autosizing-cell-using-autolayout-in-ios-9-10-84ab5cdf35a2
- https://engineering.shopspring.com/dynamic-cell-sizing-in-uicollectionview-fd95f614ef80
- https://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout#25896386