Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the default UICollectionView cell size?

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?

like image 270
Lukas Kalinski Avatar asked Sep 03 '14 12:09

Lukas Kalinski


Video Answer


1 Answers

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;
}
like image 110
Lukas Kalinski Avatar answered Sep 22 '22 23:09

Lukas Kalinski