Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify NSLineBreakMode in boundingRectWithSize?

 [text boundingRectWithSize:BOLIVIASize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT} context:nil];

That is the new replacement for

- (CGSize) sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode) lineBreakMode

However, how do I specify the lineBreakMode parameter on boundingRectWithSize?

like image 238
user4951 Avatar asked Dec 17 '13 10:12

user4951


1 Answers

use NSParagraphStyleAttributeName & NSParagraphStyle:

NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.lineBreakMode = NSLineBreakByWordWrapping; //e.g.

CGSize size = [label.text boundingRectWithSize: constrainedSize options:NSStringDrawingUsesLineFragmentOrigin attributes: @{ NSFontAttributeName: label.font, NSParagraphStyleAttributeName: paragraph } context: nil].size;
like image 82
Daij-Djan Avatar answered Nov 14 '22 22:11

Daij-Djan