美文网首页
iOS - 10.3系统 Label 下划线失效

iOS - 10.3系统 Label 下划线失效

作者: Mr_Bob_ | 来源:发表于2017-04-21 16:17 被阅读92次
前言:

iOS10.3升级后,发现项目中类似商城,会用到的一些原价的下划线失效了,主要原因是Label上的文字只要包含有“中文”,富文本字符串的中划线就会失效

WX20170421-161102@2x.png
解决方法:
  • 让富文本支持"中文"
    增加一个富文本属性:
    NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)

具体方法为:

NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:originalPriceLabel.text];
 [attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0,originalPriceLabel.text.length)];
 originalPriceLabel.attributedText = attributeMarket;

相关文章

网友评论

      本文标题:iOS - 10.3系统 Label 下划线失效

      本文链接:https://www.haomeiwen.com/subject/lbidzttx.html