rams
rams

Reputation: 49

Cell spacing in UICollectionView minimumInteritemSpacing

How to do set cell spacing in a section of UICollectionView? UICollectionView there is a property minimumInteritemSpacing, I need to set 1.0 still it not work. And I implemented the delegate method.

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  {
     return 1.0;
  }

Upvotes: 2

Views: 24317

Answers (3)

Mounika Vangala
Mounika Vangala

Reputation: 396

you can set programmatically like this

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

layout.minimumLineSpacing = 0.0;
layout.minimumInteritemSpacing = 0.0;
contestsCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];

Upvotes: 4

Greg
Greg

Reputation: 25459

This method set up spaces between cells, footer and header:

- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(20, 20, 20, 20); 
}

Upvotes: 3

Dhrumil
Dhrumil

Reputation: 3204

To check about how your collection Cells would look, you can try this in your Storyboard with the help of storyboard. First just for the sake of checking, put some static cells in your CollectionViewController like this so that your screen appears like this :

enter image description here

No you can see those cells and the spacing between them. In your case, the cells will appear with improper spacing as you have shown above. So now open with this screen open, open up the Size Inspector fron your Interface Builder. It would look something like this :

enter image description here

Now you can see some options in the size inspector window. You can adjust the size of each cell and also the spacing between them using the Min. Spacing option. And finally for equal spacing from left and right sides, use the Section Insets Option. As you change the values there, the change will be reflected in your Controller View. So you can get an idea if you want to increase/decrease some values.

Hope this helps.

Upvotes: 12

Related Questions