Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Last active February 15, 2019 05:16
Show Gist options
  • 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