中划线:
常用作折扣原价的显示。如图所示:
var throughLabel: UILabel!
private func initView(){
throughLabel = UILabel()
throughLabel.frame = CGRect(x: (self.view.frame.width / 2) - 35, y: (self.view.frame.height / 2), width: 70, height: 30)
throughLabel.text = "$ 1299.0"
let richString = NSMutableAttributedString.init(string: throughLabel.text!)
richString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSNumber.init(value: 1), range: NSRange(location: 0, length: richString.length))
throughLabel.attributedText = richString
throughLabel.textColor = UIColor.orange
self.view.addSubview(throughLabel)
}
下划线:
常用作提示文本,如图所示:
var throughLabel: UILabel!
private func initView(){
throughLabel = UILabel()
throughLabel.frame = CGRect(x: (self.view.frame.width / 2) - 35, y: (self.view.frame.height / 2), width: 70, height: 30)
throughLabel.text = "$ 1299.0"
let richString = NSMutableAttributedString.init(string: throughLabel.text!)
richString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSNumber.init(value: 1), range: NSRange(location: 0, length: richString.length))
throughLabel.attributedText = richString
throughLabel.textColor = UIColor.orange
self.view.addSubview(throughLabel)
}