zoukankan      html  css  js  c++  java
  • iOS 实现搜索关键字高亮

    /**正则匹配关键字高亮

    keyword就是需要高亮的关键字

    options:NSRegularExpressionCaseInsensitive 不区分大小写

    */

    NSMutableAttributedString* newString = [[NSMutableAttributedString alloc] initWithString:model.totalstring];

    NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:[NSString stringWithFormat:@"%@",keyWord] options:NSRegularExpressionCaseInsensitive error:nil];

    [regex enumerateMatchesInString:model.totalstring options:NSMatchingReportProgress range:NSMakeRange(0, [model.totalstring length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
    [newString addAttribute:(NSString*)NSForegroundColorAttributeName
    value:(id)[UIColor redColor]
    range:result.range];
    } ];

  • 相关阅读:
    centos7安装kde桌面
    centos7安装NVIDIA驱动
    15日报
    11日报
    14日报
    奖励加分
    课程建议
    13日报
    12日报
    每日总结1213
  • 原文地址:https://www.cnblogs.com/jiangxue-iOS/p/7908005.html
Copyright © 2011-2022 走看看