-
-
Save maninp/c6ada5379e9c404c475c to your computer and use it in GitHub Desktop.
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
- (CGFloat)heighWithFont:(UIFont *)font constrainedToSize:(CGSize)size | |
{ | |
return [self sizeWithFont:font constrainedToSize:size].height; | |
} | |
- (CGFloat)widthWithFont:(UIFont *)font constrainedToSize:(CGSize)size | |
{ | |
return [self sizeWithFont:font constrainedToSize:size].width; | |
} | |
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size | |
{ | |
CGRect stringRect; | |
if ([self respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) { | |
stringRect = [self boundingRectWithSize:size | |
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | |
attributes:@{NSFontAttributeName: font} | |
context:NULL]; | |
} else { | |
CGSize stringSize = [self sizeWithFont:font constrainedToSize:size]; | |
stringRect = CGRectMake(0, 0, stringSize.width, stringSize.height); | |
} | |
return stringRect.size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment