iOS 记录一枚有点意思的bug (字符串和数字添加删除线)

    NSString *price = [NSString stringWithFormat:@"原价:%@",model.originalPrice];
    NSMutableAttributedString*attributedString = [[NSMutableAttributedString alloc]initWithString:price];
    
    NSUInteger length = [price length];
    [attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle|NSUnderlineStyleNone) range:NSMakeRange(0, length)];
    
    [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:FontSize(14)] range:NSMakeRange(0, length)];
    [attributedString setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle), NSBaselineOffsetAttributeName : @0} range:NSMakeRange(0, length)];
    
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length)];

    self.originalPriceLabel.attributedText  = attributedString;
iOS 记录一枚有点意思的bug (字符串和数字添加删除线)_第1张图片
图片.png

别小看这行代码,没有还不行。。如果只是纯数字的还好,效果实现了。但是如果是文字和数字一起 你会神奇的发现 麻蛋 怎么横线不见了。。

iOS 记录一枚有点意思的bug (字符串和数字添加删除线)_第2张图片
图片.png

你可能感兴趣的:(iOS 记录一枚有点意思的bug (字符串和数字添加删除线))