How can I color a part of a WKInterfaceLabel

145 Views Asked by At

I have a sentence and I want to color some parts of this sentence.

For example "Turn on the lights" will become "Turn on(in blue) the lights(in red)"

Do you know if it's possible to make it with a unique label ?

If it's not possible, do you know how can I manage some labels side by side to print them correctly ? (with return line when text is too long, without white space...)

1

There are 1 best solutions below

0
Alessandro Orrù On BEST ANSWER

Just use an attributed string.

let s = NSMutableAttributedString(string: "Turn on", attributes: [NSForegroundColorAttributeName: UIColor.blueColor()])
s.appendAttributedString(NSAttributedString(string: " the lights", attributes: [NSForegroundColorAttributeName : UIColor.redColor()]))

label.setAttributedText(s)