user5513630
user5513630

Reputation: 1699

How to set collection view cell without gap between two cell in single row

I placed one collection view with one custom cell using storyboard.Totally i have 6 images so per row i have 2 images ( 2 cell).Now when i run the gap between 2 cells is much more.i need to remove all gap between all cells so how it should look like is without gap having 6 images .Now below image is what i need to remove gap enter image description here

I try to increase the width of cell using story board. But i doesn't work. Is there any idea to get with out gap between each cell in all rows ( right, top, bottom gap between all cells )

Please help me out.Thanks

But when i run in iphone 6, i am getting like this , why?? enter image description here

Upvotes: 1

Views: 815

Answers (2)

scollaco
scollaco

Reputation: 922

Make your class conform to UICollectionViewDelegateFlowLayout protocol and implement the methods:

- (CGSize)collectionView:(UICollectionView *)collectionView
              layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat width = self.collectionView.frame.size.width/2;
    return CGSizeMake(width, width);
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

   return UIEdgeInsetsZero;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {

   return 0.0;
}

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

Upvotes: 2

Ulysses
Ulysses

Reputation: 2317

You can set the minimumInteritemSpacing in the UICollectionViewFlowLayout, here in the documentation you can see more details

Like this,

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInterItemSpacing = 1;

self.collectionView.layout = flowLayout;

Source : http://nsscreencast.com/episodes/46-fun-with-uicollectionview

Upvotes: 0

Related Questions