导入第三方一些类库后,出现一些警告就是某些方法被弃用了:
如:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakModeNS_DEPRECATED_IOS(2_0,7_0, "Use -boundingRectWithSize:options:attributes:context:");
提示用:boundingRectWithSize:options:attributes:context:这个方法
这个方法:
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context
几个参数:
size:范围自己决定options :这是一个枚举类型
typedefNS_ENUM(NSInteger, NSStringDrawingOptions) {
NSStringDrawingTruncatesLastVisibleLine = 1 << 5,
NSStringDrawingUsesLineFragmentOrigin = 1 <<0,
NSStringDrawingUsesFontLeading = 1 <<1,
NSStringDrawingUsesDeviceMetrics = 1 <<3,
} NS_ENUM_AVAILABLE_IOS(6_0);
自己选一个适合的
attributes:字典
NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};
context:文本绘制的规范定义,一半为nil就可以
替换后:
NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};
CGSize textSize = [@"字符串" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
-boundingRectWithSize:options:attributes:context:用法
原文地址:http://blog.csdn.net/duoduo_333/article/details/43483415