我如何在iOS 6中强调文本?

我正在试图强调标签中的一些文字。 但是,我不知道如何获取标签中整个文本的范围。 这是我迄今为止:

NSMutableAttributedString *mat = [self.tableLabel.attributedText mutableCopy]; [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range://??]; self.tableLabel.attributedText = mat; 

我应该为范围做些什么?

对于您可能想要使用的范围:

 NSMakeRange (0, mat.length); 

喜欢这个:

 NSMutableAttributedString *mat = [self.tableLabel.attributedText mutableCopy]; [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (0, mat.length)]; self.tableLabel.attributedText = mat; 
 NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete]; [attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:[strComplete rangeOfString:strFirst]]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[strComplete rangeOfString:strSecond]]; cell.textLabel.attributedText = attributedString;