1

i have a view with different subviews including a uiviewcollection, the thing is, i don't know how dynamically modify the uicollectionview height, the sizes of the cell is a fixed size, i'm just looking a way to figure out how make the uicollectionview height dynamic to show all the items, the number os items are not fixed.

Any help?

Thank you

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
Asinox
  • 6,747
  • 14
  • 61
  • 89
  • This did the trick and it was super easy to implement: http://stackoverflow.com/a/20829728/5058757 – azizj Feb 13 '17 at 19:48

1 Answers1

0

You need to set height constraint of UICollectionView. Then Calculate your CollectionView height as per

(topSpacing + bottomSpacing + cellHeight) * number of cells (items)

then set heightConstraint again for your collectionview.

rushisangani
  • 3,195
  • 2
  • 14
  • 18
  • Thank you, but that is not working for me, i did it using self.verticalConstraint.constant = self.uiCollectionView.collectionViewLayout.collectionViewContentSize().height – Asinox Jan 21 '16 at 19:36
  • Nope, its not like that you need to set height constraint of collectionview explicitly. Initially you can set anything. When you get all cells data then calculate height like this: CGFloat height = (cellTopSpacing + callBottomSpacing+ cellHeight (or content height)) * numberOfCells then set collectionview.HeightConstraint.constant = height; – rushisangani Jan 22 '16 at 05:37