TouchMint
TouchMint

Reputation: 111

Has UILabel rich text support?

Sorry this is a noob question but I am a noob so I hope that is ok.

Say I have a label that displays this:

"I am a Label"

is it possible to make just the word "Label" bold or change its color?

thanks!

Upvotes: 1

Views: 5219

Answers (5)

virushuo
virushuo

Reputation: 660

UILabel can't support attribute. So you should use the NSAttributedString class.

For example:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"I am a Label"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(7,5)];

Then draw the AttributedString to the view in the drawRect method.

Upvotes: 4

SentineL
SentineL

Reputation: 4732

you can not do this with usual lable. Override it, or, if your text is static, use several labels, with diferent text styles. If it's just a background for something, you may put there a picture with this text

Upvotes: 0

sElanthiraiyan
sElanthiraiyan

Reputation: 6268

You can't do this directly by using the Apple frameworks and classes. But, you could do this by using the TTAttributedLabel classes. You can find the project at the below mentioned link, https://github.com/mattt/TTTAttributedLabel

Upvotes: 1

DavidLee
DavidLee

Reputation: 29

Maybe you could try to split them into two labels.

Upvotes: 0

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

No.

Have a look at TTStyledTextLabel.

Upvotes: 0

Related Questions