1

I am trying to make a grid of cells by using UICollectionView. I would remove all padding, spacing among cells. I used the layout methods and properties

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

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{
    CGSize retval = CGSizeMake(120, 120);
      return retval;
}

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

    InsetsMake(0, 0, 0, 0);
}

But I get always a space among columns.

enter image description here

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
gdm
  • 7,647
  • 3
  • 41
  • 71
  • possible duplicate of [how do you determine spacing between cells in UICollectionView flowLayout](http://stackoverflow.com/questions/13017257/how-do-you-determine-spacing-between-cells-in-uicollectionview-flowlayout) – Caleb Jul 09 '13 at 08:57
  • It is not a duplicate. Before writing the question I viewed the question you cited. – gdm Jul 10 '13 at 07:28
  • It's the same issue -- you want your cells to butt against each other with no spaces, but the collection layout distributes extra space between the cells. The duplicate question is asking for the same thing. My comment on [my answer](http://stackoverflow.com/a/13018243/643383) explains the issue in a little more detail, and the other answers explain how to create a layout that left justifies items, leaving any extra space to the right. If you're asking something different, please clarify the question. – Caleb Jul 10 '13 at 08:03

2 Answers2

2

Cells in UICollectionView are always distributed evenly (with equal horizontal margins) by default, there's no "maximum distance between cells" property. If you want no space between columns, you should either choose the cell size that will fill the entire space (i.e. 256x256 for iPad in landscape mode), or make your own custom layout by subclassing UICollectionViewLayout and using it with your collection view.

Kyr Dunenkoff
  • 8,090
  • 3
  • 23
  • 21
0

You're only setting the minimum spacing between the cells, which is all you can do. It looks like the width of your collection view is somewhat greater than the width of the cells that fit in the row, so the layout distributes the extra space between the cells. Two things you could try are:

  • set the width of the collection view to a multiple of the width of a cell

  • create your own UICollectionViewLayout subclass that arranges the cells more to your liking

Caleb
  • 124,013
  • 19
  • 183
  • 272