若有商城App 可能会有这样的需求, 为价格加上贯穿横线, 类似:$1000.00
浅谈下如何实现:
UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(10,90,200,21)];
[self.viewaddSubview:label];
label.text=@"$1000.00";
label.textAlignment=NSTextAlignmentCenter;
// 横线的颜色跟随label字体颜色改变
label.textColor= [UIColor grayColor];
NSMutableAttributedString*newPrice = [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@"¥%@",label.text]];
[newPrice addAttribute:NSStrikethroughStyleAttributeNamevalue:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:NSMakeRange(0, newPrice.length)];
label.attributedText= newPrice;