iOS:设置一段字符串每个字符不同颜色

private lazy var iOSMan : UILabel = {

let iOSMan = UILabel()

iOSMan.text = "let iOSMan = Wave"

iOSMan.sizeToFit()

iOSMan.left = 0

iOSMan.top = self.pythonMan.bottom + 5

let str = NSMutableAttributedString.init(string: iOSMan.text!)

str.addAttribute(NSForegroundColorAttributeName, value: UIColor.kBasis_Let_Color(), range: NSMakeRange(0, 3))

str.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor(), range: NSMakeRange(4, 8))

str.addAttribute(NSForegroundColorAttributeName, value: UIColor.kBasis_deepBlue_Color(), range: NSMakeRange(12,5))

iOSMan.attributedText = str

return iOSMan

}()

你可能感兴趣的:(iOS:设置一段字符串每个字符不同颜色)