boundingRectWithSize:options:attributes:context用法

Posted ios攻城狮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了boundingRectWithSize:options:attributes:context用法相关的知识,希望对你有一定的参考价值。

导入:

MBProgressHUD出警告

如:

- (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:这个方法

 

CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin; 

CGSize maxSize = CGSizeMake(maxWidth, remainingHeight);

    /*

CGSize detailsLabelSize = [detailsLabel.text sizeWithFont:detailsLabel.font 

constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];*/

    

    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};

    CGSize detailsLabelSize = [detailsLabel.text boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;

 

以及

- (CGSize)sizeWithFont:(UIFont *)font NS_DEPRECATED_IOS(2_0, 7_0, "Use -sizeWithAttributes:") __TVOS_PROHIBITED;

如下写法

CGSize labelSize = [label.text sizeWithAttributes:@{NSFontAttributeName:label.font}];

 

 

几个参数:

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就可以

 

 

 

其他的大家触类旁通把

 

以上是关于boundingRectWithSize:options:attributes:context用法的主要内容,如果未能解决你的问题,请参考以下文章