Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>--Edit--</strong></p> <p>See <a href="https://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content">How do I size a UITextView to its content?</a></p> <p>Once the text has changed, you can go back to your original solution of using the contentSize. I adjusted this code to use a <code>maxHeight</code></p> <pre><code>- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { return YES; } - (void)textViewDidChange:(UITextView *)textView { CGFloat maxHeight = 312.0f; CGFloat fixedWidth = textView.frame.size.width; CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; CGRect newFrame = textView.frame; newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), fminf(newSize.height, maxHeight)); textView.frame = newFrame; } </code></pre> <p><strong>--Original Answer--</strong></p> <p>Have you tried waiting until the text has changed and then use the NSString methods to get the size? I haven't tested this but it should get you started in the right direction.</p> <pre><code>- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { return YES; } - (void)textViewDidChange:(UITextView *)textView{ CGFloat myMaxSize = 568.0f; // Set to max height you would ever want your textView to expand to CGRect frameRect = textView.frame; CGRect rect = [textView.text boundingRectWithSize:CGSizeMake(frameRect.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: textView.font} context:nil]; CGSize size = rect.size; if (size.height &gt; myMaxSize) { size.height = myMaxSize; } frameRect.size = size; [textView setFrame:frameRect]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload