本文介绍了如何在boundingRectWithSize中指定NSLineBreakMode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[text boundingRectWithSize:BOLIVIASize选项:NSStringDrawingUsesLineFragmentOrigin属性:@ {NSFontAttributeName:FONT} context:nil];
这是
<$ p的新替代品$ p>
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode
但是,如何在boundingRectWithSize上指定lineBreakMode参数?
解决方案
使用 NSParagraphStyleAttributeName
& NSParagraphStyle
:
NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle alloc] init] ;
paragraph.lineBreakMode = NSLineBreakByWordWrapping; //例如。
CGSize size = [label.text boundingRectWithSize:constrainedSize选项:NSStringDrawingUsesLineFragmentOrigin属性:@ {NSFontAttributeName:label.font,NSParagraphStyleAttributeName:paragraph} context:nil] .size;
[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?
解决方案
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;
这篇关于如何在boundingRectWithSize中指定NSLineBreakMode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!