Created
November 5, 2015 15:19
-
-
Save youssman/21fa84b31c2405b14586 to your computer and use it in GitHub Desktop.
Calculates and returns the bounding rect for the receiver
This file contains hidden or 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)frameForText:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode { | |
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; | |
paragraphStyle.lineBreakMode = lineBreakMode; | |
NSDictionary * attributes = @{NSFontAttributeName:font, | |
NSParagraphStyleAttributeName:paragraphStyle | |
}; | |
CGRect textRect = [text boundingRectWithSize:size | |
options:NSStringDrawingUsesLineFragmentOrigin | |
attributes:attributes | |
context:nil]; | |
//Contains both width & height ... Needed: The height | |
return textRect.size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment