-1

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
    You can achieve this by using https://github.com/TTTAttributedLabel/TTTAttributedLabel or by reading this example: http://stackoverflow.com/questions/24666515/how-do-i-make-an-attributed-string-using-swift – fiks Jul 14 '16 at 09:30
  • 1
    try setAttributedText: of WKInterfaceLabel – user3349433 Jul 14 '16 at 09:32

1 Answers1

1

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)
Alessandro Orrù
  • 3,443
  • 20
  • 24