The cell size in the storyboard editor is just to help you create a cell. Since each prototype cell may be of a different size, the UICollectionView does not know what cell size should be selected for all cells. That's why you set the actual size that you want to use for your cells separately. You can do this in the designer by selecting the collection view and setting its width and height for the cell size in the size inspector in the "Collection Size" section.
Or you can override the following method and return a CGSize object that defines the size that you want to use for each cell. Using this method, you can actually have each cell of a different size:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
Example:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(100, 100); }
Your view controller must be a UICollectionViewDelegateFlowLayout delegate to call this method. Therefore, be sure to add this delegate declaration to the .h file of your file, for example:
@interface MyViewController () <UICollectionViewDelegateFlowLayout>
Alex the Ukrainian Jan 29 '13 at 15:44 2013-01-29 15:44
source share