Search code examples
iosobjective-cuicollectionviewstoryboarduicollectionviewflowlayout

UICollectionView - distance between cells?


I'm using a UICollectionView with the cell width of 67, right now I am using a flow layout.

I have 3 cells in a row with 30px space between cells. How can make that distance less, so that I can fit four cells in a row? Does this method have something to do with it?

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

Solution

  • This UICollectionViewFlowLayoutDelegate method will help you..

    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section  
      {
        return 10; // This is the minimum inter item spacing, can be more
      }
    

    One more if you need more space to arrange your cells adjust the edgeInsets also