带字符串插值的属性字符串不起作用(快速)

时间:2019-03-03 06:16:48

标签: swift string string-interpolation

我想在字符串插值中使用属性字符串。但它的工作原理与屏幕截图中显示的一样。属性字符串的格式不正确。为什么会这样?是否有其他方法可以解决此问题?

enter image description here

@IBOutlet weak var denemeLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()


        var nameString: String = "any String"
            denemeLabel.text = ""

            let nameAttribute = [NSAttributedString.Key.font: UIFont(name: "Chalkduster", size: 18)]
            let attributedNameString = NSMutableAttributedString(string: nameString, attributes: nameAttribute)

            let nsAttributedString =  NSMutableAttributedString(string:"\(attributedNameString) another String")
            denemeLabel.attributedText = nsAttributedString

    }

1 个答案:

答案 0 :(得分:0)

Xcode 10.1 Swift 4.2

next()

enter image description here