iOS - 搜索关键字在结果中高亮显示
2024-08-31 18:25:35
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];
}
最新文章
- 回到顶端js实现
- iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
- IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结
- Window 常用命令
- 获取网络状态ios(2G、3G、4G、Wifi)
- Selenium WebDriver对cookie进行处理绕过登录验证码
- 关于sql where id in 转换成数据类型 int 时失败(转)
- iOS Foundation框架 -4.NSDate类的简单用法
- URAL 2065 Different Sums (找规律)
- 【无聊放个模板系列】POJ2752 EXKMP
- sql 日期时间格式转换
- HTML5,CSS3 与 Javascript 制作视频播放器
- 李洪强漫谈iOS开发[C语言-031]-逻辑短路
- bzoj 1223: [HNOI2002]Kathy函数 数位DP 高精度
- (九)打印机驱动设置—USB接口的设置
- Windows下连接调试Asus Nexus 7 Tablet
- 64位Ubuntu14.04搭建ADT开发环境
- 开源搜索技术—Lucene、Solr
- Ants(思维)
- Java 集合 散列表hash table
热门文章
- php迭代器模式(iterator pattern)
- Elasticsearch 索引文档如何使用自动生成 Id?
- python基础语法2 流程控制 if,while,for
- PHP memcache 环形队列
- python 二、八、十六进制之间的快速转换
- python tkinter txt窗口,开线程两个卡死
- RabbitMQ六种队列模式-发布订阅模式
- pycharm中使用2to3
- python使用jieba实现中文文档分词和去停用词
- DevExpress.XtraEditors.Repository.RepositoryItem.CreateDesigner()