zoukankan      html  css  js  c++  java
  • sizeWithFont方法被弃用了,该怎么办?

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

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

    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:13]};
    CGSize size = [@“相关NSString” boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

    (转)你直接用boundingRectWithSize
    看下这个方法的描述
    另外我把我这边动态获取label尺寸的代码都贴给你看看
    CGSize size = CGSizeMake(320,2000); //设置一个行高上限
    NSDictionary *attribute = @{NSFontAttributeName: nameLabel.font};
    CGSize labelsize = [nameLabel.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine NSStringDrawingUsesLineFragmentOrigin NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

  • 相关阅读:
    LeetCode-Merge Intervals
    LeetCode-Longest Valid Parentheses
    LeetCode-Divide Two Integers
    LeetCode-Next Permutation
    LeetCode-Jump Game II
    LeetCode-Maximal Rectangle
    BZOJ 1230: [Usaco2008 Nov]lites 开关灯
    BZOJ 2839: 集合计数
    BZOJ 3211: 花神游历各国
    BZOJ 5334: [Tjoi2018]数学计算
  • 原文地址:https://www.cnblogs.com/OIMM/p/5070429.html
Copyright © 2011-2022 走看看