zoukankan      html  css  js  c++  java
  • swift 富文本 获取文本size

    var attributeString = NSMutableAttributedString(string:"welcome to hangge.com")

    //从文本0开始6个字符字体HelveticaNeue-Bold,16号
    attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold", size: 16)!,
        range: NSMakeRange(0,6))
    //设置字体颜色
    attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(),
        range: NSMakeRange(0, 3))
    //设置文字背景颜色
    attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.greenColor(),
        range: NSMakeRange(3,3))
    label.attributedText = attributeString
     
    //=======获取文本size=========

    + (CGSize)sizeWithString:(NSString *)str font:(UIFont *)font maxSize:(CGSize)maxSize

    {

        NSDictionary *dict = @{NSFontAttributeName : font};

        CGSize size =  [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

        return size;

    }

  • 相关阅读:
    [Cocos2d-x]布局与定位
    [Cocos2d-x]创建项目
    nylg-154-king 选 太子
    nylg-153-king VS king
    hdoj-2053-Switch Game
    hdoj-2052-Picture
    hdoj-2051-Bitset
    hdoj-2050-折线分割平面
    大一c语言课程设计-学籍管理系统
    hdoj-2049-不容易系列之(4)——考新郎
  • 原文地址:https://www.cnblogs.com/scycool/p/5780781.html
Copyright © 2011-2022 走看看