iOS Swift 属性字符串 NSAttributedString

效果:


iOS Swift 属性字符串 NSAttributedString_第1张图片
WechatIMG83.jpeg
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
    }

你可能感兴趣的:(iOS Swift 属性字符串 NSAttributedString)