当前位置: 首页 > 工具软件 > iOS7 Sampler > 使用案例 >

IOS7.0 sizeWithFont:constrainedToSize:lineBreakMode:方法 iOS7 Deprecated

纪晨
2023-12-01
之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个boudingRectWithSize:options:attributes:context方法来代替。

而具体怎么使用呢,尤其那个attribute

<pre name="code" class="objc">//NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:13]};
//设置段落模式
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSLineBreakByWordWrapping;
NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:13], NSParagraphStyleAttributeName: paragraph};

CGSize size = [@“相关NSString” boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;


 


 

 类似资料: