gpt4 book ai didi

ios - 在 TextView 中渲染新行

转载 作者:行者123 更新时间:2023-11-29 05:35:09 26 4
gpt4 key购买 nike

我正在尝试在 TextView 中渲染换行符。我给 textview 文本一个包含新行的值,但它不起作用。

我的代码:

@IBOutlet weak var postTextTextViewOutlet : UITextView!

let postDescription = "Testing \nNew\nLine\nIssue\n...\n...."

func configureUI() {
self.postTextTextViewOutlet.attributedText = postDescription.html2AttributedString
}

extension String {
var html2AttributedString: NSAttributedString? {
do {
return try NSAttributedString(data: Data(utf8),
options: [.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil)
} catch {
print("error:", error)
return nil
}
}
}

问题是显示时未显示换行符:

enter image description here

请大家帮忙,谢谢

最佳答案

试试这个

self.postTextTextViewOutlet.text = postDescription

关于ios - 在 TextView 中渲染新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57107364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com