iOS10.3更新后牢撼,商城APP這樣的UI:原價 “¥500 ” 類似Label設(shè)置的中劃線突然失效了拄养。
這可能是蘋果系統(tǒng)的一個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