iOS 10.3 Label的中划线失效

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22080737/article/details/79195079

开发过程中,商品价格的原价Label需要设置中划线,意外发现iOS 10.3的中划线失效了,其他系统的都正常。这应该是苹果系统本身的一个bug。

解决方法一:使用英文版的”¥”,可直接复制使用

NSString *originalPrice = [NSString stringWithFormat:@"¥%@", @"100.00"];
NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:originalPrice];
[attributeStr setAttributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0, originalPrice.length)];
_originalPriceLabel.attributedText = attributeStr;


解决方法二:让富文本支持“中文”

NSString *originalPrice = [NSString stringWithFormat:@"¥%@", @"100.00"];
NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:originalPrice];
[attributeStr setAttributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName:@(NSUnderlineStyleSingle)} range:NSMakeRange(0,market.length)];
_originalPriceLabel.attributedText = attributeStr;

猜你喜欢

转载自blog.csdn.net/qq_22080737/article/details/79195079