UITextView text content doesn't start from the top UITextView text content doesn't start from the top objective-c objective-c

UITextView text content doesn't start from the top


I had the same problem, and turns out I had to set the content offset in viewDidLayoutSubviews for it to take effect. I'm using this code to display attributed static text.

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

SWIFT 3:

override func viewDidLayoutSubviews() {    super.viewDidLayoutSubviews()    self.textView.setContentOffset(CGPoint.zero, animated: false)}


This is the only way that worked for me. I disable the scroll of the UITextView before the view is loaded and then i enable it again:

  override func viewWillAppear(_ animated: Bool) {        yourTextView.isScrollEnabled = false    }    override func viewDidAppear(_ animated: Bool) {        yourTextView.isScrollEnabled = true    }


[self.textView scrollRangeToVisible:NSMakeRange(0, 1)];

in viewDidLoad