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
  • 227,796
  • 193
  • 515
  • 708

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
  • 21,988
  • 13
  • 81
  • 109
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,804
  • 2
  • 15
  • 22