Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large Text Being Cut Off in UITextView That is Inside UIScrollView

I'm having a serious problem that I just can't seem to fix and it's driving me insane for the last two days. I have searched far and wide and I can't find a solution, even though I have tried many.

I have a UITextView inside a UIScrollView. I am able to dynamically resize the UITextView inside the scrollview to display the text. But when the UITextView contains very large text it gets cut off when I scroll almost to the end. However, the UIScrollView's frame is still being sized correctly.

I read these posts: this this and many similar ones.

The UIScrollview and UITextview are both created in the xib using AutoLayout.

Here is my current code and a screenshot as you can see the blank spot in the screenshot should be filled with text. please help.

enter image description here

- (void)viewDidAppear:(BOOL)animated {     CGRect frame = self.longDescField.frame;     frame.size.height = self.longDescField.contentSize.height;     self.longDescField.frame = frame;      self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width,  self.longDescField.contentSize.height + 200);     self.scrollView.scrollEnabled = YES;     [self.scrollView flashScrollIndicators]; } 
like image 733
sudo Avatar asked Sep 09 '13 10:09

sudo


2 Answers

This issue has existed since iOS 7 and is still present in iOS 12.

However, I wasn't able to keep the normal scrolling behaviour by setting scrollEnabled = NO before the resize, as @igz recommended. Instead I switched scrolling on and off after the resize

// Resize text view here  textView.scrollEnabled = NO; textView.scrollEnabled = YES; 

This forced the cut off text to render correctly.

like image 186
Mike Avatar answered Oct 05 '22 06:10

Mike


Thanks everyone for your help. This is ultimately what ended up working for me in iOS7.

I had to disable auto layout for this particular xib.

Then did the following:

[textView setScrollEnabled:YES]; [textView setText:text]; [textView sizeToFit]; [textView setScrollEnabled:NO]; 
like image 35
sudo Avatar answered Oct 05 '22 04:10

sudo