Reputation: 4173
I am trying to kill the margin left that the UICollectionViewCell
have as shown in the picture. I tried using all the methods that I could think of to take that margin away but nothing seems to work. All the methods are being called as I tested it with the NSLog
What do I have to do so that all the cells are cluster together with no space between them?
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 9;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(100.f, 67.f);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
NSLog(@"layout1");
return 0.0f;
}
- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
NSLog(@"layout2");
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
NSLog(@"layout3");
return 0.0f;
}
Upvotes: 0
Views: 579
Reputation: 125007
What do I have to do so that all the cells are cluster together with no space between them?
Assuming you're using UICollectionViewFlowLayout
, you should make the width of your collection view an even multiple of your cell width. Otherwise, the layout will distribute the leftover space between the cells.
You could also write your own layout class that positions all the cells right next to each other and leaves any remaining space at the end of the line, or splits it between the beginning and end of the line, or whatever you like. But that's more work.
Upvotes: 2