How to specify NSLineBreakMode in boundingRectWithSize?

守給你的承諾、 提交于 2019-12-06 05:04:40

问题


 [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?


回答1:


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;


来源:https://stackoverflow.com/questions/20631464/how-to-specify-nslinebreakmode-in-boundingrectwithsize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!