根据搜素的字符串改变label包含该字符串的文字

http://www.2cto.com/kf/201504/391811.html

     NSString *text =@"人生若只如初见";

    //判断字符串所在的位置,并不区分大小写

    NSRange range = [text rangeOfString:@"若" options:NSCaseInsensitiveSearch];

    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];

  //设置其文字的颜色

    [attStr addAttribute:NSForegroundColorAttributeName value:RGBA(0, 161, 176, 1) range:range];

  //把字符串赋值给label

    [self.nameLabel setAttributedText:attStr];

原文地址:https://www.cnblogs.com/lyz0925/p/5673968.html