I need the text of a UILabel
to be black, but have a light gray underline under the text. Is this possible with NSAttributedString
or TTTAttributedLabel
? Or is custom drawing using Core Graphics needed?
CLARIFICATION: I need a specific color text on a different color underline. Example: blue text on red underline.
Instead of creating a local
NSMutableAttributedString
and adding attributes one by one, we can always create multiple attributes in one single line (using NSDictionary symbols - @ { } ) to a specific UILabel including the actual text.Objective C:
In the above example we have set an underline which is also bold - total 2 attributes.
Swift:
You can do with
NSAttributedString
as below.Note: You can also underline particular range of string as like in this post. Also note down, it works ios6+ only.