搜索字符串中字符出现的次数,并且高亮显示
2016-03-15 15:52
399 查看
objective-c :搜索字符串中字符出现的次数,并且高亮显示
- (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;
}
- (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;
}
相关文章推荐
- 最简单地实现标签页导航-----TabLayout+ViewPager
- js获取当前页面的URL
- 【推荐】oc解析HTML数据的类库(爬取网页数据)
- HttpServletRequest 获取URL的方法及区别
- 15款Cocos2d-x游戏源码
- 如何开发Xcode插件
- MAC、IP头、TCP头、UDP头帧格式、详解
- 优化Hibernate所鼓励的7大措施:
- android 中byte[] bitmap drawable inputstream的相互转换
- 剑指offer代码解析——面试题22栈的压入、弹出序列
- which、where、locate、find的使用与区别
- 4.线程和进程
- Android中管理多个Fragment的最佳实践,完美解决保存状态与重影问题
- 剑指offer代码解析——面试题22栈的压入、弹出序列
- HMM隐Markov模型的原理及应用建模
- xml查询节点
- iOS生成开发者证书和发布者证书(新手可看)
- CentOS6.5安装与配置Mysql数据库
- < 全 > 如何编译安装Nagios
- Ajax——json