func configPrice(realPrice: String, oldPrice: String) -> Void {
let prefix = "¥" + realPrice
let suffix = "¥" + oldPrice
let string = prefix + suffix
let myAttribute = [NSAttributedStringKey.foregroundColor: UIColor.lightGray,
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 13)] as [NSAttributedStringKey : Any]
let attString = NSMutableAttributedString(string: string)
attString.addAttributes(myAttribute, range: NSRange.init(location: prefix.count, length: suffix.count))
labelPrice.attributedText = attString
}
效果:

网友评论