Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change space between cells in UICollectionView?

Tags:

I want to reduce the size between cells in row. Now it looks like:

enter image description here

I'm trying this, for reduce the size between them:

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.sectionInset = UIEdgeInsets(top: 20, left: 2, bottom: 10, right: 2) layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 0 

but it doesn't help me. What I do wrong?

like image 956
John Doe Avatar asked Feb 26 '16 14:02

John Doe


People also ask

What is UICollectionView flow layout?

Overview. A flow layout is a type of collection view layout. Items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row containing as many cells as will fit. Cells can be the same sizes or different sizes.

What is collection view layout?

A layout object determines the placement of cells, supplementary views, and decoration views inside the collection view's bounds and reports that information to the collection view. The collection view then applies the provided layout information to the corresponding views so that they can be presented onscreen.

What is compositional layout?

A compositional layout is composed of one or more sections that break up the layout into distinct visual groupings. Each section is composed of groups of individual items, the smallest unit of data you want to present. A group might lay out its items in a horizontal row, a vertical column, or a custom arrangement.

What is Minimuminteritemspacing in Swift?

For a vertically scrolling grid, this value represents the minimum spacing between items in the same row. For a horizontally scrolling grid, this value represents the minimum spacing between items in the same column.


2 Answers

//Objective c - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {         return CGSizeMake((collectionView.frame.size.width/3)-20, 100);     }  // Swift 2.0  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {     return CGSizeMake((collectionView.frame.size.width / 3) - 20, 100) }  // Swift 3.0 override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {     return CGSize(width: CGFloat((collectionView.frame.size.width / 3) - 20), height: CGFloat(100)) } 
like image 167
Yagnesh Dobariya Avatar answered Oct 17 '22 14:10

Yagnesh Dobariya


Go to the storyboard , right click on collection view and enter image description here

And Check your minimum spacing between the cell and reduce it to zero .

like image 43
Himan Dhawan Avatar answered Oct 17 '22 15:10

Himan Dhawan