您的位置:首页 > 其它

搜索字符串中字符出现的次数,并且高亮显示

2016-03-15 15:52 399 查看
objective-c :搜索字符串中字符出现的次数,并且高亮显示

- (NSMutableAttributedString *)colorData:(NSString *)withStr{

NSMutableAttributedString *dataStr = [[NSMutableAttributedString alloc] initWithString:withStr];

for (int i = 0; i < withStr.length - appDelegate.searchKeyWords.length + 1; i++) {

if ([[withStr substringWithRange:NSMakeRange(i, appDelegate.searchKeyWords.length)] isEqualToString:appDelegate.searchKeyWords])
{

NSRange range = NSMakeRange(i, appDelegate.searchKeyWords.length);

[dataStr addAttribute:NSForegroundColorAttributeName value:SETCOLOR(255, 114, 0) range:NSMakeRange(range.location,range.length)];

}

}

return dataStr;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: