Skip to content

Instantly share code, notes, and snippets.

@youssman
Created November 5, 2015 15:19
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 youssman/21fa84b31c2405b14586 to your computer and use it in GitHub Desktop.
Save youssman/21fa84b31c2405b14586 to your computer and use it in GitHub Desktop.
Calculates and returns the bounding rect for the receiver
-(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