美文网首页
swift利用富文本定向设置UILabel的内容字体颜色

swift利用富文本定向设置UILabel的内容字体颜色

作者: 只会ctrl_c_v | 来源:发表于2016-07-05 09:53 被阅读335次

//UILabel的自定义显示text字符的颜色

let textStr : String = "欢迎光临"

var mutableStr :NSMutableAttributedString=NSMutableAttributedString()

mutableStr =NSMutableAttributedString(string:textStr, attributes:nil)

//设置text的第一个字体颜色

mutableStr.addAttribute(NSForegroundColorAttributeName, value:UIColor(red:0,green:145/255,blue:63/255,alpha:1), range:NSRange(location:0, length:1))

//设置text的第二个开始,长度2的字体颜色

mutableStr.addAttribute(NSForegroundColorAttributeName, value:UIColor(red:91/255, green:47/255, blue:52/255, alpha:1), range:NSRange(location:1, length:2))

self.heavenLabel.attributedText= mutableStr

相关文章

网友评论

      本文标题:swift利用富文本定向设置UILabel的内容字体颜色

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