【问题标题】:How to add strings with different fonts in UItextField?如何在 UItextField 中添加不同字体的字符串?
【发布时间】:2020-05-11 12:54:10
【问题描述】:

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

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

【问题讨论】:

    标签: swift uitextview nsattributedstring


    【解决方案1】:

    删除

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-11
      • 2014-09-15
      • 1970-01-01
      • 2022-01-05
      • 2023-01-19
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      相关资源
      最近更新 更多