Skip to content

Instantly share code, notes, and snippets.

@ruandao
Forked from hebertialmeida/gist:9234391
Last active August 29, 2015 14:04
Show Gist options
  • Save ruandao/ee3f6e014fe9ffa61aee to your computer and use it in GitHub Desktop.
Save ruandao/ee3f6e014fe9ffa61aee to your computer and use it in GitHub Desktop.
iOS resize view 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