0

I'm using AddressBook to get an array of all records, and then displaying the names in a UITableView.

My question is, how can I baldify the correct part of the full name, like in the Contacts app? I could create a huge number of if statements, but I was wondering if there's an easier way.

Here's how I'm retrieving the names:

_person = person;
CFStringRef name = ABRecordCopyCompositeName(person);
NSString *nameString = CFBridgingRelease(name);

[self.textLabel setText:nameString];

Thanks in advance.

Sam
  • 79
  • 1
  • 1
  • 7

1 Answers1

0

Use for example NSAttributedString (you may change every attribute for every part of string). Make your UILabel to use attributed string of course

NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"];
 // for those calls we don't specify a range so it affects the whole string
[attrStr setFont:[UIFont systemFontOfSize:12]];
[attrStr setTextColor:[UIColor grayColor]];
// now we only change the color of "Hello"
[attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)];
nerowolfe
  • 4,787
  • 3
  • 20
  • 19