0

I'm working with a UICollectionView where I have to set a small gap between the margin and the cell of UICollectionView. I tried adjusting the inset of the flow layout like this but I couldn't get what I wanted.

    let flow = resturantCollection.collectionViewLayout as! UICollectionViewFlowLayout
    flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10)

Please look at the image to get an idea of what I'm trying to do.enter image description here

I'm trying to set a small gap between the cell and the margin. Is there anyway to do this?

ebby94
  • 2,981
  • 2
  • 20
  • 31
  • see this once it helps you http://stackoverflow.com/questions/28325277/how-to-set-cell-spacing-and-uicollectionview-uicollectionviewflowlayout-size-r – Anbu.Karthik May 27 '16 at 12:01

1 Answers1

0

Here is the code

//-----------------------------------------------------------------------

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

return CGSizeMake((self.view.frame.size.width - 40) / 3 , (self.view.frame.size.width - 40) / 3);

}

//-----------------------------------------------------------------------

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

//-----------------------------------------------------------------------

Here what i want is need 4 Cell to be displayed in Every screen with 10px space all sides

(self.view.frame.size.width - 40) / 3 -> 4 Cells

Prashant Tukadiya
  • 13,804
  • 3
  • 55
  • 78