iOS开发UILabel篇:iOS 8 下中划线失效的解决方法

来源:互联网 发布:java和php哪个就业好 编辑:程序博客网 时间:2024/05/28 14:56

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

如果您的问题是iOS10.3,请转至这里:iOS 10.3 Label设置的中划线突然失效了

0 0
原创粉丝点击