Pierre Charpentier
Pierre Charpentier

Reputation: 270

How can I color a part of a WKInterfaceLabel

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...)

Upvotes: -1

Views: 145

Answers (1)

Alessandro Orrù
Alessandro Orrù

Reputation: 3513

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)

Upvotes: 1

Related Questions