我们都知道给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;