/**正則匹配關鍵字高亮
keyword就是需要高亮的關鍵字
options:NSRegularExpressionCaseInsensitive 不區分大小寫
*/
NSMutableAttributedString* newString = [[NSMutableAttributedString alloc] initWithString:model.totalstring];
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:[NSString stringWithFormat:@"%@",keyWord] options:NSRegularExpressionCaseInsensitive error:nil];
[regex enumerateMatchesInString:model.totalstring options:NSMatchingReportProgress range:NSMakeRange(0, [model.totalstring length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
[newString addAttribute:(NSString*)NSForegroundColorAttributeName
value:(id)[UIColor redColor]
range:result.range];
} ];
第二種方法
// NSRange range = [[content lowercaseString] rangeOfString:[specialStr lowercaseString]];
// NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:content];
// [attribute addAttribute:NSForegroundColorAttributeName value:[UIColor blue] range:range];
// return attribute;