我正在实现 UICollectionViewDelegateFlowLayout
的 collectionView:layout: sizeForItemAtIndexPath:(NSIndexPath*)indexPath
方法,为了计算新的单元格大小,我必须访问默认的。
我的问题是:如何从我的代码访问 Storyboard中定义的默认单元格大小?
最佳答案
我在做这道题的时候找到了答案,所以为了和大家分享一下,这里有一些示例代码:
- (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;
}
关于objective-c - 如何获得默认的 UICollectionView 单元格大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25644101/