0

I'm using UICollectionViewDelegateFlowLayout to make my size and height of the collectionViewCell but when I use this one, the constraint in the cell are not updated.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: UIScreen.main.bounds.width - 30, height: self.height)
}

So the delegate method set the correct size but element in the cell are cuted (not updated). My cell constraint are set in the storyboard.

Makaille
  • 1,488
  • 1
  • 16
  • 38
  • can you add your autolayout code or show storyboard/xib screen layout – Suhit Patil Feb 14 '19 at 08:54
  • @SuhitPatil I can't but my constraint are set with leading / trailing / top. and proportional to the contentView for the height. – Makaille Feb 14 '19 at 09:01
  • you can use self sizing cells for using dynamic heights for collection view cells https://stackoverflow.com/questions/44187881/uicollectionview-full-width-cells-allow-autolayout-dynamic-height/44352072 – Suhit Patil Feb 14 '19 at 09:16

1 Answers1

1

Without too much detail, I guess you may need:

viewWillLayoutSubviews()

Called to notify the view controller that its view is about to layout its subviews.

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621437-viewwilllayoutsubviews

or

layoutSubviews()

https://developer.apple.com/documentation/uikit/uiview/1622482-layoutsubviews

Tieda Wei
  • 558
  • 4
  • 13