How to format some text as bold within a UILabel?

1.2k views Asked by At

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?

2

There are 2 answers

0
Glorfindel On BEST ANSWER

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;
0
agy On

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