0

I have this code

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
   if(indexPath.row==0)
  {
    return CGSizeMake(320, 143.5);
  }
   else if (indexPath.row==1)
  {
    return CGSizeMake(320, 143.5);
  }
   else
  {
    return CGSizeMake(160, 160); //This line
  }  
}

I intend to have a two columns in line without gap, but returning 160 size will cause the cell have two rows with one cell each. so for the time being I set it to (155,155) but it leaves gap between the cell.

no space between cell

so how to remove that gap?

Update

solved after using @AlwaysWannaLearn solution!

but don't forget to set the inset.

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

   return UIEdgeInsetsMake(0,0, 0, 0);  // top, left, bottom, right
}

no gap!

xeravim
  • 463
  • 7
  • 20

1 Answers1

0

Open up your Interface Builder and check if the CollectionView has Minimum Spacing set or not. If its set to some value, make it zero and then set your cell size to 160. That should work just fine. Here is a screen shot of the Interface Builder. See the Min. Spacing value for cells. Set it to zero.

enter image description here

Hope this helps.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34
  • I just tested it on one of the CollectionViews here. It works for me. Check out for the section inset values and make them zero. Also check if the width of your screen is exactly 320 or slightly more. – Dhrumil Jun 12 '14 at 05:00
  • Thank you for reminding me about the inset! now it solved! thanks! – xeravim Jun 12 '14 at 05:55