标签:ring view uicolor event style name span att search
self.labelContent.attributedText = [self highlightText:self.searchStr inStr:searchModel.eventDesc]; - (NSAttributedString *)highlightText:(NSString *)keyword inStr:(NSString *)str { NSRange range = [str rangeOfString:keyword]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str]; if (range.length > 0) { [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range]; } else { } return [[NSAttributedString alloc]initWithAttributedString:attrStr]; }
- (NSAttributedString *)highlightText:(NSString *)keyword inStr:(NSString *)str { NSRange range = [str rangeOfString:keyword]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str]; if (range.length > 0) { [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range]; } else { } return [[NSAttributedString alloc]initWithAttributedString:attrStr]; } #pragma mark UITableViewDelegate - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { NSString *str = [self.strs objectAtIndex:indexPath.row]; cell.textLabel.attributedText = [self highlightText:self.searchTextField.text inStr:str]; }
标签:ring view uicolor event style name span att search
原文地址:https://www.cnblogs.com/gongyuhonglou/p/11084507.html