美文网首页iOS Development
Swift - lable 显示不同颜色字体

Swift - lable 显示不同颜色字体

作者: 71150ce14a00 | 来源:发表于2016-12-23 13:57 被阅读18次

class MyLable: UILabel {

override func awakeFromNib() {

}

override func layoutSubviews() {

super.layoutSubviews()

let attributeStr = NSMutableAttributedString(string: self.text!)

attributeStr.addAttribute(NSForegroundColorAttributeName, value:UIColor.red , range:NSRange(location: 0,length: 2))

}

func changeTextColor(text: String, color: UIColor, range: NSRange) -> NSAttributedString {

let attributeStr = NSMutableAttributedString(string: text)

attributeStr.addAttribute(NSForegroundColorAttributeName, value:color , range: range)

return attributeStr

}

//

}

相关文章

网友评论

本文标题:Swift - lable 显示不同颜色字体

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