UILabel.attributedText添加删除线无效的问题
2017-04-18 本文已影响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];