UICollectionView单元格之间的距离不变

时间:2014-10-14 13:06:58

标签: ios objective-c iphone ipad uicollectionview

我正在开发iOS应用程序,其中我一度陷入困境。

我正在使用水平collectionView,我想减少两个collectionViewCell之间的间距,我写了下面的代码片段,但它没有改变单元格之间的间距。

.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.....
}

我能够看到我的细胞,但细胞之间的间距没有变化,我希望细胞之间没有间距......

请提前帮助和感谢

3 个答案:

答案 0 :(得分:1)

最后通过写这个问题解决了问题,

flowLayout.minimumInteritemSpacing=0.0f;
flowLayout.minimumLineSpacing=0.0f;

答案 1 :(得分:0)

UICollectionViewFlowLayout本身公开了两个属性; minimumInteritemSpacing用于设置同一行中项目之间的间距,minimumLineSpacing用于设置网格中项目行之间的间距。您是否尝试在初始化时设置布局的属性?

flowLayout.minimumInteritemSpacing = 0.0f;

答案 2 :(得分:0)

单击集合视图流布局,并在大小检查器中更改单元格之间的最小间隔。 "在文件大纲#34;