zoukankan      html  css  js  c++  java
  • 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就可以

    其他的大家触类旁通把

  • 相关阅读:
    NFS 服务器实验
    ssh服务实验
    dhcp服务实验
    邮件服务器
    搭建 DNS 服务器
    搭建 web 服务器
    Feign下的数据传递
    基于Spring Cloud Feign的Mock工具
    Git 使用注意事项
    基于redisson的延迟队列
  • 原文地址:https://www.cnblogs.com/godlovexq/p/5622683.html
Copyright © 2011-2022 走看看