iOS10.3更新后,商城APP這樣的UI:原價(jià) “¥500 ” 類似Label設(shè)置的中劃線突然失效了。
這可能是蘋果系統(tǒng)的一個(gè)bug。
根本原因:UILabel上的文字只要包含有“中文”,富文本字符串的中劃線就會(huì)失效,我們可通過以下兩種方式解決。
第一種方式:人民幣符號(hào)“¥”和“¥”,使用前面一個(gè)即可。
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;
第二種方式:讓富文本支持“中文”
增加一個(gè)富文本屬性: 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;
簡(jiǎn)單記錄下:
原文地址:
http://blog.csdn.net/ymh1989qwe/article/details/70954275?utm_source=itdadao&utm_medium=referral