直接代码
NSString * str=@"fjsalfasdfdasfasdjf我很好";
NSMutableAttributedString * attriStr=[[NSMutableAttributedString alloc]initWithString:str];
NSRange range = [str rangeOfString:@"我很好"];
[attriStr addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:range];
UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];
label.attributedText=attriStr;
[self.view addSubview:label];
好出来效果是
多个keyword用这个方法
<pre name="code" class="objc"> NSError *error;
NSString *strRegex = keyWord;
NSReg