Skip to content

Instantly share code, notes, and snippets.

@zakdances
Created May 9, 2013 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakdances/5551141 to your computer and use it in GitHub Desktop.
Save zakdances/5551141 to your computer and use it in GitHub Desktop.
- (CGSize)sizeThatFits:(CGSize)size
{
NSMutableArray *bottoms = [NSMutableArray array];
for (UIView *view in self.subviews) {
NSNumber *bottom = [NSNumber numberWithFloat:view.center.y + CGRectGetMidY(view.bounds)];
[bottoms addObject:bottom];
}
[bottoms sortUsingComparator:^NSComparisonResult(NSNumber *a, NSNumber *b) {
return [a compare:b];
}];
NSMutableArray *rights = [NSMutableArray array];
for (UIView *view in self.subviews) {
NSNumber *right = [NSNumber numberWithFloat:view.center.x + CGRectGetMidX(view.bounds)];
[rights addObject:right];
}
[rights sortUsingComparator:^NSComparisonResult(NSNumber *a, NSNumber *b) {
return [a compare:b];
}];
CGFloat width = ((NSNumber *)[rights lastObject]).floatValue;
CGFloat height = ((NSNumber *)[bottoms lastObject]).floatValue;
return CGSizeMake(width,height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment