0

I have an iOS UILabel that needs some of the text to be normal and some of the text to be bold. The bold text is actually supposed to be a link to another part of the app, but for now, I'm just reacting to tapping on the entire label. How can I format some of the text to be bold?

Andrew
  • 212,236
  • 189
  • 499
  • 691

2 Answers2

1

Use the attributedText property:

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"This is a test."];
[text addAttribute:NSFontAttributeName
          value:[UIFont boldSystemFontOfSize:12]
          range:NSMakeRange(0, 4)];
label.attributedText = text;
Glorfindel
  • 20,880
  • 13
  • 75
  • 99
0

You need to use NSAttributedString. Please look at this answer to see an example: Any way to bold part of a NSString?

Community
  • 1
  • 1
agy
  • 2,789
  • 2
  • 13
  • 22