I\'m using a UICollectionView with two prototype cells. The prototype cells have different widths and contain different controls (image view and web view). I\'m definitely ret
In Swift you can call sizeForItemAtIndexPath delegate method to set the size for each cell.
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if indexPath.row == 0 {
// Set the size for cell no. 0
}else if indexPath.row == 1 {
// Set the size for cell no. 1
}
}
I hope that helps. Thanks!
I had a Similar Issue, I set a breakpoint on the sizeForItemAt and it was being called for every cell I had on my collection, however, the size set in code was never being reflected on the device.
While looking at other collections in my project I noticed the Collection View Flow Layout was slightly different in the collection with the issue.
This helped me solve my issue.
However the size of the cell will not be dynamic with what is in your sizeForItemAt
If all your cells are the same size, you should simply set the UICollectionView
's Cell size properties to the same as the UICollectionViewCell
's size properties.