您的位置:首页 > 移动开发 > IOS开发

ios 文字变色

2016-04-02 10:22 381 查看
extension UILabel{

func paint(aText:String,aColor:UIColor?,startIndex:Int,endIndex:Int){
self.text = aText
if (attributedText != nil && aColor != nil){
let attr = NSMutableAttributedString(attributedString: self.attributedText!)
attr.addAttribute(NSForegroundColorAttributeName, value: aColor!, range: NSMakeRange(startIndex, startIndex + endIndex))
attributedText = attr
}
}

func paint(aFirstText:String,aSecondText:String,sSecondTextColor:UIColor){
self.text = aFirstText + aSecondText
if (attributedText != nil ){
let attr = NSMutableAttributedString(attributedString: self.attributedText!)
attr.addAttribute(NSForegroundColorAttributeName, value: sSecondTextColor, range: NSMakeRange(aFirstText.length(), aSecondText.length()))
attributedText = attr
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  swift