美文网首页
iOS 搜索字符串中字符 高亮显示 2015-04-28

iOS 搜索字符串中字符 高亮显示 2015-04-28

作者: blaze冰叔 | 来源:发表于2019-07-19 14:49 被阅读0次
- (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;
} 

相关文章

网友评论

      本文标题:iOS 搜索字符串中字符 高亮显示 2015-04-28

      本文链接:https://www.haomeiwen.com/subject/yrxslctx.html