label 关键字标红(富文本)
作者:
张家杰仔 | 来源:发表于
2017-04-05 10:30 被阅读67次NSString *keyword = @"开源";
NSString *result = @"开源中国社区";
// 设置标签文字
NSMutableAttributedString *attrituteString = [[NSMutableAttributedString alloc] initWithString:result];
// 获取标红的位置和长度
NSRange range = [result rangeOfString:keyword];
// 设置标签文字的属性
[attrituteString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont systemFontOfSize:17]} range:range];
// 显示在Label上
label.attributedText = attrituteString;
本文标题:label 关键字标红(富文本)
本文链接:https://www.haomeiwen.com/subject/qfytattx.html
网友评论