gpt4 book ai didi

ios - UITextView 初始滚动位置不为 0

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:56 24 4
gpt4 key购买 nike

我有一个 UITextView 来显示文章的标题和内容。这是我的代码:

static func setTextViewRichText(textView: UITextView, html: String, title: String) {

do {
let titleText = NSAttributedString(string: title + "\n", attributes: [NSFontAttributeName: UIFont(name: "Helvetica", size: 20)!])
let contentText = try NSAttributedString(data: html.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSNumber(unsignedLong: NSUTF8StringEncoding)], documentAttributes: nil)
let text = NSMutableAttributedString(attributedString: titleText)
text.appendAttributedString(contentText)
textView.attributedText = text

} catch let err as NSError {
NSLog("%s", err)
textView.text = title + "\n" + html
}
}

初始滚动位置不是0,这不是我想要的。我没有在代码中设置任何属性。

最佳答案

首先尝试布局:

textView.layoutIfNeeded()
textView.attributedText = myText

或者您可以重置滚动偏移量:

textView.attributedText = myText
textView.contentOffset = .zero

关于ios - UITextView 初始滚动位置不为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34602155/

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