iOS Development

Swift - lable 显示不同颜色字体

2016-12-23  本文已影响18人  71150ce14a00

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

}

//

}

上一篇下一篇

猜你喜欢

热点阅读