I am trying to implement a CollectionView
.
When I am using Autolayout, my cells won't change the size, but their alignment.
Now I would rather want to change their sizes to e.g.
//var size = CGSize(width: self.view.frame.width/10, height: self.view.frame.width/10)
I tried setting in my CellForItemAtIndexPath
collectionCell.size = size
it didn't work though.
Is there a way to achieve this?
edit:
It seems, that the answers will only change my CollectionView width and height itself. Is there are conflict in Constraints possible? Any ideas on that ?
If one is using storyboard and overriding UICollectionViewDelegateFlowLayout then in swift 5 and Xcode 11 also set Estimate size to None
Try below method
Finally got the answer. You should extend
UICollectionViewDelegateFlowLayout
This should be working with answers above.
in Swift3 and Swift4 you can change cell size by adding UICollectionViewDelegateFlowLayout and implementing it's like this :
or if create UICollectionView programmatically you can do it like this :
Swift 5 Programmatically