Created
March 25, 2014 21:40
-
-
Save xtreme-daniel-crampton/9771969 to your computer and use it in GitHub Desktop.
Returns a CGSize for a multi-line string.
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)adjustedSizeWithFont:(UIFont *)font fromDefaultSize:(CGSize)defaultSize { | |
CGFloat additionalHeight = 0.0f; | |
NSDictionary *attributes = @{NSFontAttributeName : font}; | |
CGRect rect = [self boundingRectWithSize:CGSizeMake(defaultSize.width, MAXFLOAT) | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:attributes | |
context:nil]; | |
//Doesn't matter what the string is here. Just need to get the height of one line of text. | |
CGRect singleLineRect = [@"X" boundingRectWithSize:CGSizeMake(defaultSize.width, MAXFLOAT) | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:attributes | |
context:nil]; | |
additionalHeight -= CGRectGetHeight(singleLineRect); | |
additionalHeight += CGRectGetHeight(rect); | |
return CGSizeMake(defaultSize.width, defaultSize.height + ceil(additionalHeight)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment