【发布时间】:2017-09-25 00:56:36
【问题描述】:
我正在尝试显示带有一些文本的分数。分数显示在句子的中间,我希望分数的字体比文本的其余部分大。
我的代码如下:
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...
我觉得我在做一些愚蠢的事情,但无法弄清楚它是什么。任何帮助将不胜感激!
【问题讨论】:
-
您可以在此处找到解决方案。 stackoverflow.com/questions/31647653/…
-
你应该设置你的标签属性文本而不是你的后期文本属性developer.apple.com/documentation/uikit/uilabel/…
标签: ios swift nsattributedstring