Search code examples
iosuicollectionviewuicollectionviewcelluicollectionviewlayout

Swift collection view cell greater than collection view frame


enter image description hereI have a collectionview that can scroll horizontally. The problem I have is this (can't upload screenshot so I did an illustration):

Green is my collectionView background, pink is my collectionview cells background.

I have like 10 cells, the last cell's content view always exceeds my collection view trailing anchor constraints for some reason.

I created my own flow layout class, I set the itemSize and estimatedItemSize like this:

self.itemSize = UICollectionViewFlowLayout.automaticSize
self.estimatedItemSize = CGSize(width: 32, height: 36)

Any ideas why?


Solution

  • I can reproduce this if I turn off "Clip to Bounds", so my recommendation would be to use collectionView.clipsToBounds = true, or make sure the "Clip to Bounds" box is checked in your xib/storyboard.