I have UICollectionView in which I would like to have no spacing between the cells. However despite my all effort I can't seem to remove the the space,
Code
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
Extra Info
- Cell width is 234
- UICollectionView width is 703
You can't do that with the default UICollectionViewFlowLayout. Although you can use another layout, like a subclass of it. I'm using this class to set the spacing explicitly:
From this. You need to change minimumInteritemSpacing and minimumLineSpacing.
Actually, you won't be able to set a parameter to achieve your goal using
UICollectionViewFlowLayout
because it plays with the cell spacing to properly align all items in the screen, and that's the reason why they set the cells spacing as a minimum. If your cell size are fixed you can play with theViewCollection
Size
so that all cells and margins perfectly fit in it.Try setting 0(zero) to the properties of UICollectionView: Min Spacing For Cells and For Lines
I have fixed similar issue by unchecking "Relative to margin" in size inspector.
Change the spacing in storyBoard or programmatically.
or
Below did trick for me.
Last line is very important where we are assigning the layout