• 搜索匹配关键字


    //改变关键字颜色

    //调用在你的cell中  tableview代理 cellforrow

    //返回单元格内容

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        

        static NSString *str = @"ID";

        WHXSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:str];

        if (cell == nil) {

            cell = [[WHXSearchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];

        }

       

        if (_isarray==YES) {

            SearchModel *mode = _dataArray[indexPath.row];

            cell.index = NO;

            cell.model = mode;

        }else{

            SearchModel *mode = _searchArray[indexPath.row];

            if (_searchArray.count==1) {

                cell.index = YES;

            }

            cell.delegat = self;

            [cell setModel:mode];

            //搜索匹配关键字

    //        [cell.namelabel setAttributedText:[self attrStrFrom:mode.labelName searchStr:_TextField.text]];

            [cell.namelabel setAttributedText:[self rangeSearchLight:mode.labelName searchString:_TextField.text]];

        }

       

        return cell;

        

    }

    //改变状态

    - (NSMutableAttributedString *)rangeSearchLight:(NSString *)string searchString:(NSString *)searchString

    {

        NSString *strAfterDecodeByUTF8AndURI = [searchString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSRange range = [string rangeOfString:strAfterDecodeByUTF8AndURI];

        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:string];

        [attr setAttributes:@{NSForegroundColorAttributeName:QBCOLOR_RGB(87, 139, 237)}

                      range:range];

        return attr;

    }

     //改变字体和颜色方法

    //- (NSMutableAttributedString *)attrStrFrom:(NSString *)titleStr searchStr:(NSString *)searchStr

    //{

    //        NSMutableAttributedString *arrString = [[NSMutableAttributedString alloc]initWithString:titleStr];

    //        // 设置前面几个字串的格式:粗体、红色

    //        [arrString addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold" size:18.0],

    //                                   NSForegroundColorAttributeName:QBCOLOR_RGB(87, 139, 237)

    //                                        }

    //                                range:[titleStr rangeOfString:searchStr]];

    //        return arrString;

    //}//

  • 相关阅读:
    分布式数据库中间件Mycat百亿级数据存储(转)
    大文本字符串滤重的解决方案(转)
    java处理大文本2G以上
    Mysql binlog详解
    varnish squid nginx比较
    java运行时内存分类
    redis rdb aof比较
    LeetCode 94 ——二叉树的中序遍历
    线性代数之——向量空间
    线性代数之——A 的 LU 分解
  • 原文地址:https://www.cnblogs.com/whx060900/p/9718435.html
Copyright © 2020-2023  润新知