iOS 10.3 UILabel设置的中划线失效问题

iOS10.3更新后,商城APP这样的UI:原价 “¥500 ” 类似Label设置的中划线突然失效了。
这可能是苹果系统的一个bug。
根本原因:UILabel上的文字只要包含有“中文”,富文本字符串的中划线就会失效,我们可通过以下两种方式解决。
第一种方式:人民币符号“¥”和“¥”,使用前面一个即可。

NSString *market = [NSString stringWithFormat:@"¥%@",@"500"];
NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:market];
[attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0,market.length)];

_marketLabel.attributedText = attributeMarket;

第二种方式:让富文本支持“中文”

增加一个富文本属性: NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)

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

_marketLabel.attributedText = attributeMarket;

简单记录下:
原文地址:
http://blog.csdn.net/ymh1989qwe/article/details/70954275?utm_source=itdadao&utm_medium=referral

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容