如何在 UItextField 中添加不同字体的字符串?

How to add strings with different fonts in UItextField?

我正在尝试添加具有不同字体参数的两部分文本。 但他们总是从第一个字符串中获得价值。 还有一件奇怪的事,字体颜色是独立设置的。

let descriptionTextView: UITextView = {
    let view = UITextView()


    let attributedText = NSMutableAttributedString(string: "Text", attributes:
        [.font:UIFont.boldSystemFont(ofSize: 20),
    .foregroundColor: UIColor.blue])

    attributedText.append(NSAttributedString(string: "\n\n\n Other text", attributes:
        [.font: UIFont.italicSystemFont(ofSize: 5),
         .foregroundColor: UIColor.gray]))

    view.attributedText = attributedText


    view.translatesAutoresizingMaskIntoConstraints = false
    view.textAlignment = .center
    view.font = UIFont.boldSystemFont(ofSize: 20)
    view.isEditable = false
    view.isScrollEnabled = false

    return view
}()

This is how it look in simulator

移除

view.font = UIFont.boldSystemFont(ofSize: 20)