UICollectionView: Self sizing cell with a UILabel on iOS 10
All we needed was a simple UICollectionView with just one cell that contained a label ...
All we needed was a simple UICollectionView
with just one cell that contained a label with an unknown amount of text. We just wanted to use the default flow layout and to let auto-layout do the work; we did not want to implement a custom layout. The label was pinned to all sides of the cell’s content view. It did not work. The text inside of the label would get truncated in weird and sometimes random ways.
We ended up using a table view with estimatedRowHeight
set to a constant and rowHeight
set to UITableView.automaticDimension
. The label was still pinned to the content view. It worked like a charm.
Subscribe to The infinite monkey theorem
Get the latest posts delivered right to your inbox