【发布时间】:2023-04-02 18:13:01
【问题描述】:
我对两个字符串的组合有问题:
let finalMutableString = NSMutableAttributedString()
let attributedDot = NSAttributedString(string: " ●", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 7)])
let firstPartString = NSAttributedString(string: "Sample text", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 17)])
finalMutableString.append(attributedDot)
finalMutableString.append(firstPartString)
label.attributedText = finalMutableString
整个文本的字体大小为7.0,而不仅仅是attributedDot。
为什么这是它的行为方式?文本应该有不同的大小
【问题讨论】:
-
您的代码对我来说很好用。除了
XCode将NSFontAttributeName替换为NSAttributedString.Key.font。 -
该项目适用于 Swift 3,因此 key.font 可能不可用
标签: ios swift nsattributedstring nsmutableattributedstring