Anuradh S Anuradh S - 1 year ago 167
iOS Question

Multiple text color for UILabel text does not work in swift 3.0

I tried to change the text color for the part of a

UILabel
like below.

func changetheColor () {
let staticStrng : String = "Zave receipt"
var mymutableAttributeString = NSMutableAttributedString()
mymutableAttributeString = NSMutableAttributedString(string: staticStrng)

mymutableAttributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSRange(location: 5,length: 7))
saveReceiptLabel.text = mymutableAttributeString.string
}


this doesn't work,What am I doing wrong. hope your help.

Answer Source

Change this :

    saveReceiptLabel.attributedText = mymutableAttributeString.string