美文网首页iOS技术分享、交流
UILabel设置多种字体颜色、尺寸

UILabel设置多种字体颜色、尺寸

作者: 楓葉乄神無月 | 来源:发表于2016-11-25 20:45 被阅读5次
    let str1 = NSMutableAttributedString(string: "每积累签到5天送50个名额")
    // 设置数字5为红色
    str1.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(5, 1))
    // 设置数字5的字体为:Arial, size为20
    str1.addAttribute(NSFontAttributeName, value: UIFont(name: "Arial", size: 20)!, range: NSMakeRange(5, 1))
    // 设置数字50为红色
    str1.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(8, 2))
    // 添加下划线
    str.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(integer: NSUnderlineStyle.StyleSingle.rawValue), range: NSMakeRange(3, str.length - 3))
    detailLbl2.attributedText = str1
    

    相关文章

      网友评论

        本文标题:UILabel设置多种字体颜色、尺寸

        本文链接:https://www.haomeiwen.com/subject/gfewpttx.html