swift 属性字符串 NSAttributedString

2018-02-06  本文已影响2721人  jzhang
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
    }

效果:


WechatIMG83.jpeg
上一篇下一篇

猜你喜欢

热点阅读