字符串中关键字高亮
// 高亮顯示字符串中的關(guān)鍵字NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.title];NSError *error = nil;NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:self.keyword options:0 error:&error];
NSArray *matches = [regex matchesInString:self.titleoptions:0range:NSMakeRange(0, self.title.length)];[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, [attributedString length])];for (NSTextCheckingResult *match in matches){NSRange matchRange = [match rangeAtIndex:0];[attributedString addAttribute:NSForegroundColorAttributeNamevalue:[UIColor colorWithHexString:@"ff6e11"]range:matchRange];}
//UILabelself.titleLbl.attributedText = attributedString;
//UILabelself.titleLbl.attributedText = attributedString;
?
轉(zhuǎn)載于:https://www.cnblogs.com/allanliu/p/4778357.html
總結(jié)
- 上一篇: 火箭固体燃料是什么材料
- 下一篇: 德州2022年建筑工程副高职称评审结果什