Reputation: 15
I am trying to make my UICollectionView
's cells fill the whole width, but it just looks like this:
I tried something like this:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height+140)
}
But it doesn't do anything. Tips?
Upvotes: 1
Views: 1262
Reputation: 4744
You need to use sizeForItemAt
instead of sizeForItemAtIndexPath
. sizeForItemAtIndexPath Asks the delegate for the size of the specified item’s cell.
You need to Use Swift 3+:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height+140)
}
Upvotes: 1