gpt4 book ai didi

ios - UICollectionViewFlowLayout 的行和列

转载 作者:行者123 更新时间:2023-11-29 04:02:19 28 4
gpt4 key购买 nike

给定一个具有流式布局的 UICollectionView,计算 Collection View 的列数(垂直方向)或行数(水平方向)的最简单方法是什么?

最佳答案

我的做法(假设所有元素具有相同的大小):

- (void) countRowsAndColumns
{
NSArray *layouts = [collectionViewLayout layoutAttributesForElementsInRect:self.collectionView.bounds];
NSMutableSet *columns = [NSMutableSet set];
NSMutableSet *rows = [NSMutableSet set];
for (UICollectionViewLayoutAttributes *layout in layouts)
{
if (layout.representedElementCategory != UICollectionElementCategoryCell) continue;
CGFloat x = layout.frame.origin.x;
[columns addObject:@(x)];
CGFloat y = layout.frame.origin.y;
[rows addObject:@(y)];
}
_columnCount = columns.count;
_rowCount = rows.count;
}

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

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