Makaille
Makaille

Reputation: 1666

Constraint not updated after using UICollectionViewDelegateFlowLayout

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.

Upvotes: 0

Views: 120

Answers (1)

Tieda Wei
Tieda Wei

Reputation: 602

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

Upvotes: 1

Related Questions