UITextView 改变高度而不是滚动
默认情况下,当文本视图的高度无法容纳太多文本时,UITextView 的 contentView 将变为可滚动。
我想禁用此功能,而是更新 UITextView 的高度以适合文本。我这样做的原因是因为我将 UITextView 添加为 UIScrollView 的子视图,它应该处理滚动,就像在本机邮件应用程序中一样(当您输入文本时,整个视图向上滚动,而不仅仅是文本视图任何
人都有一些想法/之前遇到过同样的问题吗?
By default, the UITextView's contentView becomes scrollable when there is too much text to fit into the textview based on it's height.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样做非常简单:
这应该设置文本视图的高度以适当地适合其所有内容。
It is very simply done like this:
This should set the height of the textview to appropriately fit all of its content.
一些小变化:
添加字体高度可以在拼写错误时为自动更正框提供空间。
UITextView
还应该设置为不滚动:Few little changes:
Adding the font height gives room for the autocorrection box when you spell something incorrectly.
The
UITextView
should also be set to not scroll: