UITextView 改变高度而不是滚动

UITextView change height instead of scroll(UITextView 改变高度而不是滚动)
本文介绍了UITextView 改变高度而不是滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

默认情况下,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 的子视图,它应该处理滚动,就像在本机邮件应用程序中一样(当您输入文本时,整个视图向上滚动,而不仅仅是 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 改变高度而不是滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)