Search code examples
iosobjective-cautolayoutuitextview

UITextView always appears scrolled to bottom of content?


I am using storyboard with auto layout, scene contains UITextView with some text in it, you can see in following image:

enter image description here

But whenever i move to this scene in running application, it would be like following:

enter image description here
I have researched it a lot and tried following code, even then it not worked for me:

[self.scrollView setContentOffset:CGPointZero animated:NO];

Any help would be appreciated.


Solution

  • Try following, may it help:

    [yourTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:YES];
    

    OR

    set the content offset in viewDidLayoutSubviews for it to take effect.

    - (void)viewDidLayoutSubviews {
    [yourTextView setContentOffset:CGPointZero animated:NO];
    }
    

    OR

    in viewDidLoad

    [yourTextView scrollRangeToVisible:NSMakeRange(0, 1)];