美文网首页
UILabel.attributedText添加删除线无效的问题

UILabel.attributedText添加删除线无效的问题

作者: 试毒小二 | 来源:发表于2017-04-18 15:27 被阅读238次

如果字符串中有特殊符号和中文,attrDic中必须添加

NSBaselineOffsetAttributeName

否则添加删除线无效。

完整代码:

NSDictionary *attrDic = @{
                              NSFontAttributeName:[UIFont systemFontOfSize:14.f],
                              NSForegroundColorAttributeName:UIColorFromHexNumber(0xFF8585, 1),
                              NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),
                              NSStrikethroughColorAttributeName:UIColorFromHexNumber(0xFF8585, 1),
                              NSBaselineOffsetAttributeName:@(0)
                              };
    NSString *originalPriceString = [NSString stringWithFormat:@"¥%.2f", 654.2156];
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:originalPriceString attributes:attrDic];
    [yourLabel.attributedText:attrStr];

相关文章

网友评论

      本文标题:UILabel.attributedText添加删除线无效的问题

      本文链接:https://www.haomeiwen.com/subject/qjafzttx.html