Zhen Zhen - 1 year ago 73
Objective-C Question

Any way to bold part of a NSString?

Is there any way to bold only part of a string?
For example:

Approximate Distance: 120m away


Answer Source

What you could do is use an NSAttributedString.

NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName];
NSString *yourString = ...;
NSRange boldedRange = NSMakeRange(22, 4);

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString];

[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName 

[attrString endEditing];
//draw attrString here...

Take a look at this handy dandy guide to drawing NSAttributedString objects with Core Text.