Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Last active February 15, 2019 05:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hebertialmeida/9234391 to your computer and use it in GitHub Desktop.
Save hebertialmeida/9234391 to your computer and use it in GitHub Desktop.
Resize UIView to fit subviews
- (void)resizeToFitSubviews:(UIView *)view
{
float w, h;
for (UIView *v in view.subviews) {
float fw = v.frame.origin.x + v.frame.size.width;
float fh = v.frame.origin.y + v.frame.size.height;
w = MAX(fw, w);
h = MAX(fh, h);
}
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, w, h)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment