roshan posakya
roshan posakya

Reputation: 1030

How to decrease vertical space between two cell in collectionview?

enter image description here

How to decrease the vertical space between two cell in collectionview?

Upvotes: 0

Views: 888

Answers (3)

Alessandro Francucci
Alessandro Francucci

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

Uma Madhavi
Uma Madhavi

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

Philou
Philou

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

Related Questions