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

- (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)