gpt4 book ai didi

ios - UITextView 中的 AttributedString 在顶部被修剪

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

我在 UITextView 中使用属性字符串。可以找到示例 Playground here

这是对正在发生的事情的快速总结。

UITextView 存在填充问题,可以使用 this 解决感谢@Fattie

我在 UITextView 中设置了属性字符串。

然后我使用 sizeThatFits 计算 textView 的高度我猜这个方法给了我正确的高度。

但是当我运行它时,顶部的文本被修剪,底部留有一些空间。请从 here 运行示例 Playground 。

我想这可能是 textView 带有默认填充的原因,但我不完全确定。

奇怪的是,我对 UILabel 进行了相同的尝试,并且在相同的设置下它似乎工作得非常好。取消注释 UILabel 后,您可以在上面的 Playground 中尝试相同的操作。

谁能告诉我为什么 UITextView 会出现这个问题?

最佳答案

使用后解决

let htmlText = text.data(using: .utf8, allowLossyConversion: false)!
let mutableText = try! NSAttributedString(
data: htmlText,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil)

关于ios - UITextView 中的 AttributedString 在顶部被修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613581/

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