Skip to content

Instantly share code, notes, and snippets.

@frijole
Created February 4, 2016 14:36
Show Gist options
  • Save frijole/55b511e86e2d662a286a to your computer and use it in GitHub Desktop.
Save frijole/55b511e86e2d662a286a to your computer and use it in GitHub Desktop.
Resize a collection view to its content with AutoLayout via http://stackoverflow.com/a/26232188
@interface DynamicCollectionView : UICollectionView
@end
@implementation DynamicCollectionView
- (void) layoutSubviews
{
[super layoutSubviews];
if (!CGSizeEqualToSize(self.bounds.size, [self intrinsicContentSize]))
{
[self invalidateIntrinsicContentSize];
}
}
- (CGSize)intrinsicContentSize
{
CGSize intrinsicContentSize = self.contentSize;
return intrinsicContentSize;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment