Skip to content

Instantly share code, notes, and snippets.

@kylehowells
Created March 19, 2013 22:46
Show Gist options
  • Save kylehowells/5200854 to your computer and use it in GitHub Desktop.
Save kylehowells/5200854 to your computer and use it in GitHub Desktop.
Automatically set the height of a UIScrollView to fit it's content.
CGFloat scrollViewHeight = 0.0f;
CGFloat scrollViewWidth = 0.0f;
for (UIView *view in scrollView.subviews) {
CGFloat height = (view.frame.size.height + view.frame.origin.y);
scrollViewHeight = ((height > scrollViewHeight) ? height : scrollViewHeight);
CGFloat width = (view.frame.size.width + view.frame.origin.x);
scrollViewWidth = ((width > scrollViewWidth) ? width : scrollViewWidth);
}
[scrollView setContentSize:(CGSizeMake(scrollViewWidth, scrollViewHeight))];
@ekpekodzo
Copy link

Hi ! How to use this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment