//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
网友评论