mymutableAttributeString

mymutableAttributeString

我尝试更改UILabel部分的文本颜色,如下所示。

func changetheColor () {
        let staticStrng : String = "Zave receipt"
        var mymutableAttributeString = NSMutableAttributedString()
        mymutableAttributeString = NSMutableAttributedString(string: staticStrng)

        mymutableAttributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSRange(location: 5,length: 7))
        saveReceiptLabel.text = mymutableAttributeString.string
    }


这不起作用,我在做什么错。希望你的帮助。

最佳答案

改变这个:

    saveReceiptLabel.attributedText = mymutableAttributeString.string

08-05 23:50