NSMutableAttributedString(在搜索的时候,关键词加高亮)
NSString *oldPrise = @"¥ 5888";
NSUInteger length = [oldPrise length];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 400, 80)];
label.font = [UIFont systemFontOfSize:40];
[self.view addSubview:label];
// 设置删除线
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:oldPrise];
[attribute addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(2, length - 2)];
// 设置画线颜色和字体颜色
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 1)];
// 字符串字体放大
#warning 关键词高亮,搜索时用
[attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:70] range:NSMakeRange(4, 1)];
[label setAttributedText:attribute];
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 1)];