我们在做开发过程中难免会遇到商品打折价格处理,也就是给label添加中划线效果如下图所示
划线价格示意图
具体实现思路:
label 有个attributedText属性,我们需要设置下这个属性代码如下
UILabel *label = [[UILabel alloc]init];
label.text = @"USD 215.00"
label.textColor = MOGOLabelColor;
label.font = regularFont(12 * fontScale);
NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:label.text attributes:attribtDic];
label.attributedText = attribtStr;
bingo,中划线搞定
同理吗,label添加下划线只需要设置attributedText这个属性
NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:label.text attributes:attribtDic];
bingo,下划线搞定
网友评论