Iphone – How to make a UITextView Expand with the text like the Notes app

iphonesdkuitextview

How can you make a UITextView expand with the text that is inside of it?

Best Answer

you could try this...

UITextView *textView; // your UITextView
NSString *text; // the text that you want to place in the UITextView
UIFont *textViewFont; // the font that you are using for your UITextView

CGSize size = {255,2000.0f};  //The default width, and max height you want to use

CGSize newSize = [text sizeWithFont:textViewFont
                 constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];

textView.frame = CGRectMake(0,0,newSize.width, newSize.height);