Anuradh S Anuradh S - 7 months ago 103
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

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.


Change this :

    saveReceiptLabel.attributedText = mymutableAttributeString.string