Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView change height instead of scroll

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?

like image 903
Tom Irving Avatar asked Apr 05 '10 19:04

Tom Irving


1 Answers

It is very simply done like this:

CGRect frame = textView.frame;

frame.size = textView.contentSize;

textView.frame = frame;

This should set the height of the textview to appropriately fit all of its content.

like image 148
jhauberg Avatar answered Nov 09 '22 00:11

jhauberg