要实现一个小UI,如下图:
![](https://img.haomeiwen.com/i1293851/17034e28b07de854.png)
底部这个价格的实现可以使用一个居中的View,上面加两个Label,再加一个View作为删除线,但是这样略显繁琐. 我们可以使用一个Label的富文本来实现这样的效果.
// 价格
let lowestAttr: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.hex("555555"),
.font: UIFont.systemFont(ofSize: 14.auto())
]
let originalAttr: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.hex("898989") ,
.font: UIFont.helveticaNeue(9.auto()),
.strikethroughStyle: NSUnderlineStyle.single.rawValue,
.strikethroughColor: UIColor.hex("898989"),
.baselineOffset: 0
]
let lowestStr = "¥\((item.lowestPrice ?? 0) / 100)"
let originalStr = " ¥\((item.originPrice ?? 0) / 100)"
priceLabel.attributedText = lowestStr.toAttr(lowestAttr) + originalStr.toAttr(originalAttr)
网友评论