Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel with two different color text

How can i have a UILabel with two different colors for the font? I will have text in two different strings and i want to make text with first string as red and second as green. The length of both the string is variable.

like image 257
pankaj Avatar asked Oct 17 '10 08:10

pankaj


2 Answers

Try TTTAttributedLabel. It's a subclass of UILabel that supports NSAttributedStrings, which would make it easy to have multiple colors, fonts, and styles in the same string.


Edit: Alternatively, if you don't want the 3rd party dependency and are targeting iOS 6, UILabel now has the attributedText property.

like image 87
mattt Avatar answered Oct 16 '22 15:10

mattt


You can't do this within a UILabels. But my suggestion is that instead of using multiple UILabel just concentrate on NSAttributedString. Find UIControllers that draw NSAttributedString because UILabel, UITextView do not support NSAttributedString.

PS: if you plan to distribute an iOS6 or later application, as UILabel now support NSAttributedString, you should use UILabel directly instead of OHAttributedLabel as it is now natively supported by the OS.

like image 25
KingofBliss Avatar answered Oct 16 '22 15:10

KingofBliss