如何获取默认的UICollectionView单元格大小?

时间:2014-09-03 12:17:02

标签: objective-c uicollectionview

我正在实施UICollectionViewDelegateFlowLayout collectionView:layout: sizeForItemAtIndexPath:(NSIndexPath*)indexPath方法,并计算新的单元格大小,我必须访问默认单元格。

我的问题是:如何从我的代码中访问storyboard中定义的默认单元格大小?

1 个答案:

答案 0 :(得分:25)

我在撰写这个问题时找到了答案,因此,只是为了与您分享,这里有一些示例代码:

- (CGSize) collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath {

    // Get the default cell size as defined in storyboard:
    CGSize defaultSize = [(UICollectionViewFlowLayout*)collectionViewLayout itemSize];

    if (something) {
        return defaultSize;
    }

    CGSize newSize = defaultSize;
    newSize.height *= 2;

    return newSize;
}
相关问题