0

I am developing iOS app in which i got stuck at one point.

I am using horizontal collectionView, i want to reduce the spacing between two collectionViewCell, i have wrote the below code snippet but it doesn't change the spacing between the cells.

.h class

@property (strong, nonatomic) IBOutlet UICollectionView *CollectnVw;

.m class

- (void)viewDidLoad{
   [_CollectnVw registerNib:[UINib nibWithNibName:@"FilterCustomCell" bundle:nil] forCellWithReuseIdentifier:@"collectionViewCell"];
    _CollectnVw.backgroundColor = [UIColor clearColor];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(100, 35)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [_CollectnVw setCollectionViewLayout:flowLayout];
    [_CollectnVw setAllowsSelection:YES];
    _CollectnVw.delegate=self;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [FilterNameArr count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell" forIndexPath:indexPath];
    UILabel *titleLabel = (UILabel *)[cell viewWithTag:96];
    [titleLabel setText:[FilterNameArr objectAtIndex:indexPath.row]];

    cell.layer.borderWidth=1.0f;
    cell.layer.borderColor=[UIColor blueColor].CGColor;
    return cell;
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 50; // This is the minimum inter item spacing, Doesn't changing.....
}

I am able to see my cells but spacing between the cells not changing, i want zero spacing between the cells...

please help and thanks in advance

Krunal
  • 6,440
  • 21
  • 91
  • 155
  • did you try to use image of size specified here. [flowLayout setItemSize:CGSizeMake(100, 35)]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; – Sheshnath Oct 14 '14 at 13:18
  • I have already wrote this 2 lines in my `viewDidLoad` plz check code – Krunal Oct 14 '14 at 13:19
  • sorry but i mean image size of 100,35 , so that we can assure, it's not occupying unnecessary space. – Sheshnath Oct 14 '14 at 13:21

3 Answers3

1

Finally problem has been solved by writing this,

flowLayout.minimumInteritemSpacing=0.0f;
flowLayout.minimumLineSpacing=0.0f;
Krunal
  • 6,440
  • 21
  • 91
  • 155
0

The UICollectionViewFlowLayout exposes two properties itself; minimumInteritemSpacing which sets the spacing between items in the same row, and minimumLineSpacing which sets the spacing between lines of items in the grid. Have you tried just setting the property of your layout when you initialise it?

flowLayout.minimumInteritemSpacing = 0.0f;
Tim Edwards
  • 261
  • 5
  • 8
0

click on collection view flow laytout and in size inspector change min spaceing between cell. "IN Document Outline"

johny kumar
  • 1,270
  • 2
  • 14
  • 24