iOS 中设置下划线失效不显示

今天测试提出了bug,说没有按照UI图设置下划线。不对呀,我用模拟器和真机都测了,正常显示。一看测试的版本为10.3,下划线没有。

 

之前在设置下划线的时候:
NSMutableAttributedString*newPrice = [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@"%@", tex]];
 
 [newPrice addAttribute:NSStrikethroughStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, newPrice.length)];
 
后来查找原因,得知在10.3 增加一个富文本属性: NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)
 
    

  NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:tex];

  [attribtStr setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle],   NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0, tex.length)];

  self.originalLab.attributedText = attribtStr;

 

 

posted @ 2018-08-03 09:33  小小鸟菜  阅读(798)  评论(0编辑  收藏  举报