Anuradh S Anuradh S - 1 year ago 195
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.

Answer Source

Change this :

    saveReceiptLabel.attributedText = mymutableAttributeString.string
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download