如果字符串中有特殊符号和中文,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];
网友评论