Created
May 9, 2013 22:41
-
-
Save zakdances/5551143 to your computer and use it in GitHub Desktop.
Size
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
- (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