UITextView更改高度而不是滚动 [英] UITextView change height instead of scroll
问题描述
默认情况下,当文本视图的高度超出文本视图时,UITextView的contentView变得可滚动。
By default, the UITextView's contentView becomes scrollable when there is too much text to fit into the textview based on it's height.
我想禁用此功能相反,更新UITextView的高度以适应文本。我这样做的原因是因为我将UITextView添加为UIScrollView的子视图,它应该处理滚动,就像在本机Mail应用程序中一样(当你输入文本时,整个视图向上滚动,而不仅仅是textview 。
I'd like to disable this and instead, update the height of the UITextView to fit in the text. The reason I'm doing this is because I'm adding the UITextView as a subview of a UIScrollView which should handle the scrolling, much like in the native Mail app (when you enter text, the whole view scrolls up, not just the textview.
任何人都有一些想法/之前遇到过同样的问题?
Anyone got some ideas / has run into the same problem before?
推荐答案
这样做非常简单:
CGRect frame = textView.frame;
frame.size = textView.contentSize;
textView.frame = frame;
这应该设置textview的高度以适合其所有内容。
This should set the height of the textview to appropriately fit all of its content.
这篇关于UITextView更改高度而不是滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!