Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView content going under UINavigationBar

I have a UITextView inside a UIViewController that uses auto layout to pin it to 0 on all sides (so it fills the whole screen). I also have this view being pushed using UINavigationController.

I'm running into a weird error where if the UITextView has enough text so that it runs off the screen, then content gets set under the UINavigationBar. If there is not enough text to fill the screen the layout of the text doesn't go under the UINavigationBar.

Here is what's happening, this is when there is enough text that it goes off the screen and you need to scroll to view all of it.

enter image description here

I've tried:

  • Setting the content inset of the UITextView.

  • Made sure the UINavigationBar isn't translucent.

  • Tried setting this self.automaticallyAdjustsScrollViewInsets = NO;

like image 393
random Avatar asked Jul 09 '15 17:07

random


2 Answers

Inside viewDidLoad of viewController where your textView is, add this:

self.edgesForExtendedLayout = UIRectEdgeNone;
like image 185
Uros19 Avatar answered Sep 29 '22 13:09

Uros19


I'm not sure why the problem was occurring but this fixed it:

- (void)viewDidLayoutSubviews {
    if (self.textView) {
        [self.textView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
    }
}
like image 43
random Avatar answered Sep 29 '22 14:09

random