Skip to content

Instantly share code, notes, and snippets.

@edwardean
Forked from frijole/DynamicCollectionView.m
Created September 8, 2016 12:08
Show Gist options
  • Select an option

  • Save edwardean/a2aac17dade2cdfd1cc9078976ae7bd6 to your computer and use it in GitHub Desktop.

Select an option

Save edwardean/a2aac17dade2cdfd1cc9078976ae7bd6 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