Note that there are some explanatory texts on larger screens.

plurals
  1. POResizing UITextView automatically
    text
    copied!<p>I'm a beginner in iOS development, and I have trouble resizing automatically a UITextView.</p> <p>I created a Master-Detail Application. On my DetailViewController.xib I added a ScrollView that encompass a Label for the title, an image and under this image, a TextView in order to put a description that the user posted.<br> The problem is that the description depends on what my WebService returns, so I need it to be resized automatically.</p> <p>Here's my code:</p> <pre><code>- (void)configureView { ... self.detailDescriptionTextView.text = [self.detailItem valueForKey:@"adDescription"]; CGRect frame = self.detailDescriptionTextView.frame; frame.size.height = self.detailDescriptionTextView.contentSize.height; self.detailDescriptionTextView.frame = frame; ) </code></pre> <p>The problem is that the TextView gets the content correctly but it doesn't resize at all.. I looked for an answer for a while and most of answers are what I tried... </p> <p>Thanks for your help. </p> <p>EDIT : I realized something. In order to put some elements under the description, I've put a very small TextView for the description in the Interface Builder, is it a problem? If it is, how could I put other elements under this TextView, because there would be no more space on the Interface Builder no? </p> <p>EDIT 2 : I finally succeeded. It seems like the problem was that I created the TextView by Interface Builder. By creating it programmatically, it worked perfectly. Here's my code if it can help someone: </p> <pre><code>UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 195, 280, 10)]; textView.text = [self.detailItem valueForKey:@"adDescription"]; textView.font = [UIFont fontWithName:@"Hevlatica" size:14]; [self.scrollView addSubview:textView]; CGRect descriptionFrame = textView.frame; descriptionFrame.size.height = textView.contentSize.height; textView.frame = descriptionFrame; </code></pre> <p>Thanks for your help.</p>
 

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