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

问题描述 投票:0回答:1

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

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个回答
0
投票

删除

view.font = UIFont.boldSystemFont(ofSize: 20)
© www.soinside.com 2019 - 2024. All rights reserved.