gpt4 book ai didi

ios - uicollectionview 上的两列

转载 作者:技术小花猫 更新时间:2023-10-29 10:49:17 33 4
gpt4 key购买 nike

如何在 UICollectionView 中获得两列,它们占据整个空间,没有任何边距或间隙,就像我在下面绘制的图片一样:enter image description here

我尝试使用以下代码:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(160, 160);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}

但得到了这个结果:

enter image description here

最佳答案

通过实现 UICollectionViewDelegateFlowLayout协议(protocol),您可以找到许多实现 UICollectionView 布局的方法。

collectionView:layout:minimumInteritemSpacingForSectionAtIndex:
collectionView:layout:minimumLineSpacingForSectionAtIndex:

应该足以解决这个问题。

您还可以实现 numberOfItems 和 numberOfSections 来指定行数、列数。
或者,您可以将单元格的大小指定为(UICollectionView 的宽度)/(您想要的列数)- 单元格之间的一些偏移量
在 cellForItemAtIndexPath 中。
默认情况下,单元格由此计算并相应排列。只需减小大小,您就会看到多列。 Ref1 Ref2

关于ios - uicollectionview 上的两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23317106/

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