gpt4 book ai didi

ios - UICollectionView 单元格之间的距离不变

转载 作者:行者123 更新时间:2023-11-29 02:35:59 25 4
gpt4 key购买 nike

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

我正在使用水平collectionView,我想减少两个collectionViewCell之间的间距,我已经编写了下面的代码片段,但它不会改变之间的间距细胞。

.h 类

@property(强,非原子)IBOutlet UICollectionView *CollectnVw;

.m 类

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

我能够看到我的单元格,但单元格之间的间距没有改变,我希望单元格之间的间距为零...

请帮助并提前致谢

最佳答案

写到这里终于解决了问题,

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

关于ios - UICollectionView 单元格之间的距离不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26361629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com