-1

As users search journals, I want to display a portion of the journal and the search term bolded in the detailTextLabel in UITableViewCell.

So like, SEARCH "today"

1/19/2014 Bright and sunnday, today is going to be a ...

How do you bold that word today, but not the rest of it?

cell.detailTextLabel.text = note.content;
coolcool1994
  • 3,085
  • 3
  • 32
  • 38
  • 1
    You use an [NSAttributedString](http://stackoverflow.com/questions/3482346/how-do-you-use-nsattributedstring). [Heres another example](http://stackoverflow.com/questions/3586871/bold-non-bold-text-in-a-single-uilabel) – MendyK Mar 03 '15 at 03:32
  • 3
    possible duplicate of [Any way to bold part of a NSString?](http://stackoverflow.com/questions/6013705/any-way-to-bold-part-of-a-nsstring) – aksh1t Mar 03 '15 at 03:33
  • would bolding NSString would make detailTextLabel bolded that part too? I think NSString doesn't strictly apply to detailTextLabel, but Ill try it again. I think I have tried that one point – coolcool1994 Mar 03 '15 at 03:35

1 Answers1

2

detailTextLabel has the method setAttributedText so you can make an attributedText which you can customize dramatically, and then you can set it.

NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:note.content];
        NSRange boldedRange = NSMakeRange(0, 5);//        NSRange range = [displayingContent rangeOfString:self.notesSearchBar.text options:NSCaseInsensitiveSearch];

        [attributedText addAttribute: NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] range:boldedRange];
        [cell.detailTextLabel setAttributedText: attributedText];
coolcool1994
  • 3,085
  • 3
  • 32
  • 38