在Swift中,我怎样才能改变一部分string的属性?

我正试图用一些文字显示分数。 分数显示在一个句子的中间,我希望字体的分数大于文本的其余部分。

我的代码如下:

let fontSizeAttribute = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 43)] let myString = String(describing: Int(finalScore!.rounded(toPlaces: 0))) let attributedString = NSAttributedString(string: myString, attributes: fontSizeAttribute) scoreLabel.text = "Your score is \(attributedString)%, which is much higher than most people." 

我看不出这个实现有什么问题,但是当我运行它时,它说:“你的分数是9 {NSFont =”UITCFont:0x7f815 …

我觉得我正在做一些愚蠢的事情,但不知道它是什么。 任何帮助,将不胜感激!

请检查 :

 let fontSizeAttribute = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 43)] let myString = String(describing: Int(finalScore!.rounded(toPlaces: 0))) let partOne = NSMutableAttributedString(string: "Your ") let partTwo = NSMutableAttributedString(string: myString, attributes: fontSizeAttribute) let partThree = NSMutableAttributedString(string: "%, which is much higher than most people.") let attributedString = NSMutableAttributedString() attributedString.append(partOne) attributedString.append(partTwo) attributedString.append(partThree) scoreLabel.attributedText = attributedString