ios 文字变色

来源:互联网 发布:怎么申请淘宝卖家 编辑:程序博客网 时间:2024/05/17 23:05
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        }    }    }

0 0