15
我正在实现UICollectionViewDelegateFlowLayout的collectionView:layout:sizeForItemAtIndexPath:(NSIndexPath *)indexPath方法,并计算新的单元格大小,我必须访问默认的一个。如何获取默认的UICollectionView单元大小?
我的问题是:如何从我的代码中访问故事板中定义的默认像元大小?
我正在实现UICollectionViewDelegateFlowLayout的collectionView:layout:sizeForItemAtIndexPath:(NSIndexPath *)indexPath方法,并计算新的单元格大小,我必须访问默认的一个。如何获取默认的UICollectionView单元大小?
我的问题是:如何从我的代码中访问故事板中定义的默认像元大小?
我找到了答案,同时组成了这个问题,因此,只是与大家分享,这里的一些示例代码:
- (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;
}