ios 实现价钱打折效果 数字上划横线

时间:2023-02-08 20:12:14

//.h 拖住一个label

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

//.m
NSMutableAttributedString * priceAttrString =[[NSMutableAttributedString alloc]initWithString:@"#1212.00"];

/**
* @author 李凯利, 16-09-13 14:09:10
* 添加样式
* @param NSUnderlineStyleSingle 单线
*
* @param range 需要划线的字符索引
*/
[priceAttrString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, priceAttrString.length)];
/**
* @author 李凯利, 16-09-13 14:09:27
*
* 添加属性文本
*/
self.priceLabel.attributedText = priceAttrString;

_priceLabel.textColor =[UIColor grayColor];