美文网首页
swift 属性字符串 NSAttributedString

swift 属性字符串 NSAttributedString

作者: jzhang | 来源:发表于2018-02-06 13:38 被阅读2721次
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

相关文章

网友评论

      本文标题:swift 属性字符串 NSAttributedString

      本文链接:https://www.haomeiwen.com/subject/gddgzxtx.html