I'm implementing the UICollectionViewDelegateFlowLayout
's collectionView:layout: sizeForItemAtIndexPath:(NSIndexPath*)indexPath
method, and to calculate the new cell size, I have to access the default one.
My question is: How do I access the default cell size as defined in storyboard, from my code?
I found the answer while composing this question, thus, just to share with you, here's some sample code:
- (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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With