Search code examples
iosobjective-ciphoneuilabelnsattributedstring

Objective c - Multiple colors in a label


What is the easiest way to have a label with different colors?

For example I want to present the message:
"John Johnson sent you a message"

But I want that John Johnson will be in blue color
and the rest of the message in black color.


Solution

  • In UILabel basically impossible. If you want to this you must override drawTextInRect should be executed. But I will recommend OHAttributedLabel. this is have a attributedString is a textcolor can be set to specify a range.