Skip to content

Instantly share code, notes, and snippets.

@james-b-kelly
Last active August 29, 2015 14:07
Show Gist options
  • Save james-b-kelly/6d1494828f5f1a6fd072 to your computer and use it in GitHub Desktop.
Save james-b-kelly/6d1494828f5f1a6fd072 to your computer and use it in GitHub Desktop.
UICollectionViewFlowLayout
//In UICollectionViewCell subclass implementation
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
layoutAttributes.size = CGSizeMake(layoutAttributes.frame.size.width, layoutAttributes.frame.size.height);
return layoutAttributes;
}
//In your view controller (containing the UICollectionView).
//In @interface
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
//In viewDidLoad
self.layout = [[UICollectionViewFlowLayout alloc] init];
[self.collectionView setCollectionViewLayout:self.layout];
//In viewWillAppear
self.layout.estimatedItemSize = CGSizeMake(160.0, 44.0); //E.g. for half-width cells.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment