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

    其他的大家触类旁通把

  • 相关阅读:
    四校联考【20171001】
    C语言基础知识
    页表和TLB
    python
    Cache组织方式
    On the Spectre and Meltdown Processor Security Vulnerabilities
    latex-组织文本
    深入理解计算机系统
    深入理解计算机系统-计算机系统漫游
    逻辑地址到物理地址的转换
  • 原文地址:https://www.cnblogs.com/godlovexq/p/5622683.html
Copyright © 2020-2023  润新知