Reputation: 1030
How to decrease the vertical space between two cell in collectionview?
Upvotes: 0
Views: 888
Reputation: 1660
The method is: minimumLineSpacingForSectionAt
.
Just specify in it the spacing value that you want to have. Doc description:
For a vertically scrolling grid, this value represents the minimum spacing between successive rows.
For changing the minimum spacing between items in the same row, (I suppose you need this too) use: minimumInteritemSpacingForSectionAt
.
Upvotes: 0
Reputation: 4917
Add these lines while creating collection view layout
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
layout.itemSize = CGSize(width: screenWidth/2, height: screenWidth/2)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
collectionView!.collectionViewLayout = layout
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if indexPath.row == 0
{
return CGSize(width: screenWidth, height: screenWidth/2)
}
return CGSize(width: screenWidth/2, height: screenWidth/2);
}
Upvotes: 2
Reputation: 107
In the attribute inspector, when clicking on your collection view, you have a tab "Show Size Inspector". You can modify min spacing and section insets to get the result that you want. screenshot
Upvotes: 0