我們都知道給Label設置中劃線、下劃線等等,可以使用富文本NSMutableAttributedString
原價不設置,¥100 中間設置中劃線
NSString *market = @"原價:¥100"
NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:market];
[attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(3,market.length)];
_marketLabel.attributedText = attributeMarket;
_marketLabel.hidden = NO;
以上方式iOS 8上失效了,搞不清,原來得這麼處理
iOS 8上必須從0開始,如下:
NSString *market = @"原價:¥100"
NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:market];
[attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleNone]} range:NSMakeRange(0,3)];//**iOS 8需要加上這句**
[attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(3,market.length)];
_marketLabel.attributedText = attributeMarket;
_marketLabel.hidden = NO;