iOS10.3 UILable中划线失效问题

Posted HEJJY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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中划线失效问题的主要内容,如果未能解决你的问题,请参考以下文章

IOS7中动态计算UILable的高度

UILabel添加中划线下划线

iOS UILable 文字添加图片 (文字前面,中间,后面添加图)

iOS UILable 高度自适应

iOS-Swift3富文本(UILable文本图文混排)

UITableViewCell 中多个 UIlable 的自动布局