-
-
Save ruandao/ee3f6e014fe9ffa61aee to your computer and use it in GitHub Desktop.
iOS resize view to fit subviews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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