【问题标题】:Rows and columns of UICollectionViewFlowLayoutUICollectionViewFlowLayout 的行和列
【发布时间】:2013-03-29 19:50:49
【问题描述】:

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

【问题讨论】:

    标签: ios uicollectionview uicollectionviewlayout


    【解决方案1】:

    我的 hackish 方式(假设所有元素的大小相同):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多