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 > ) {
[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 > ) {
[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];
}

最新文章

  1. 回到顶端js实现
  2. iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
  3. IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结
  4. Window 常用命令
  5. 获取网络状态ios(2G、3G、4G、Wifi)
  6. Selenium WebDriver对cookie进行处理绕过登录验证码
  7. 关于sql where id in 转换成数据类型 int 时失败(转)
  8. iOS Foundation框架 -4.NSDate类的简单用法
  9. URAL 2065 Different Sums (找规律)
  10. 【无聊放个模板系列】POJ2752 EXKMP
  11. sql 日期时间格式转换
  12. HTML5,CSS3 与 Javascript 制作视频播放器
  13. 李洪强漫谈iOS开发[C语言-031]-逻辑短路
  14. bzoj 1223: [HNOI2002]Kathy函数 数位DP 高精度
  15. (九)打印机驱动设置—USB接口的设置
  16. Windows下连接调试Asus Nexus 7 Tablet
  17. 64位Ubuntu14.04搭建ADT开发环境
  18. 开源搜索技术—Lucene、Solr
  19. Ants(思维)
  20. Java 集合 散列表hash table

热门文章

  1. php迭代器模式(iterator pattern)
  2. Elasticsearch 索引文档如何使用自动生成 Id?
  3. python基础语法2 流程控制 if,while,for
  4. PHP memcache 环形队列
  5. python 二、八、十六进制之间的快速转换
  6. python tkinter txt窗口,开线程两个卡死
  7. RabbitMQ六种队列模式-发布订阅模式
  8. pycharm中使用2to3
  9. python使用jieba实现中文文档分词和去停用词
  10. DevExpress.XtraEditors.Repository.RepositoryItem.CreateDesigner()