Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Thanks!

like image 635
Zhen Avatar asked May 16 '11 06:05

Zhen


1 Answers

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                     value:boldFontName                    range:boldedRange];  [attrString endEditing]; //draw attrString here... 

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

like image 183
Jacob Relkin Avatar answered Oct 16 '22 10:10

Jacob Relkin