Как сделать UITextView Expand с текстом, как приложение Notes - PullRequest
2 голосов
/ 20 января 2010

Как сделать так, чтобы UITextView расширялся за счет текста внутри него?

Ответы [ 2 ]

5 голосов
/ 20 января 2010

Вы можете попробовать это ...

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);
0 голосов
/ 09 мая 2012

Вы можете попробовать это ..

CGRect frame = textView.frame;
frame.size.height = [textView contentSize].height;
textView.frame = frame;
...