首页 > 代码库 > iOS10.3 UILable中划线失效问题
iOS10.3 UILable中划线失效问题
iOS10.3系统的一个Bug,在UILable中含有中文时,中划线会失效
NSString *priceStr = [NSString stringWithFormat:@"%.2f元",payInfo.originalPrice];
1、原来添加中划线方式(在iOS10.3系统后失效)
// NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
// NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:priceStr attributes:attribtDic];
2、解决办法
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:priceStr];
[attribtStr setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0, priceStr.length)];
self.originLable.attributedText = attribtStr;
iOS10.3 UILable中划线失效问题