1

I'm having a dilemma maybe someone can help. I followed this tutorial that showed me how to dynamically adjust the height of a collectionview to match the height of the text. https://possiblemobile.com/2016/02/sizing-uicollectionviewcell-fit-multiline-uilabel/

if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout { flowLayout.estimatedItemSize = CGSizeMake(1, 1) }

cell.label.preferredMaxLayoutWidth = 50

But the issue I'm having is now the collection view wraps around the text instead of conforming to collectionView.bounds.width. So when i have text that is smaller than the collectionview width, the cell wraps around the text. I want the cell to match the height of the text but have a set width set to collectionview bounds. How could I achieve this?

  • You have a great answer to your problem [here](http://stackoverflow.com/questions/26143591/specifying-one-dimension-of-cells-in-uicollectionview-using-auto-layout) written by algal – Ocunidee Jan 06 '17 at 23:07
  • Try flowLayout.estimatedItemSize = CGSizeMake(collectionView.bounds.width, 1) but make sure your collection view already has it's proper width at this time. – RTasche Jan 06 '17 at 23:29

0 Answers0