Reputation: 6490
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
Upvotes: 0
Views: 1292
Reputation: 6490
Finally problem has been solved by writing this,
flowLayout.minimumInteritemSpacing=0.0f;
flowLayout.minimumLineSpacing=0.0f;
Upvotes: 1
Reputation: 1270
click on collection view flow laytout and in size inspector change min spaceing between cell. "IN Document Outline"
Upvotes: 0
Reputation: 261
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;
Upvotes: 0