zoukankan      html  css  js  c++  java
  • 搜索匹配关键字

    //改变关键字颜色

    //调用在你的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;

    //}//

  • 相关阅读:
    visual studio code for mac 的对齐快捷键
    ios 抓取真机的网络包
    iOS 引入framework的常见问题和原理
    iOS 4种开发者身份的官方说明
    iOS NSObject 的 isa 属性的类型 Class
    iOS 子类初始化方法中 为什么要使用 self = [super init] 对self进行赋值
    Linux和windows下修改tomcat内存
    idea将项目打成war包
    web.xml引入 xml (tomcat 7.0.52) 以上版本报错
    ideal 切换git和svn
  • 原文地址:https://www.cnblogs.com/whx060900/p/9718435.html
Copyright © 2011-2022 走看看