1

I have a TextView control in my ViewController with a whole bunch of text in it. Too much to display at once.

When the controller loads the text that show is about in the middle of the complete text. I can scroll to the top or the bottom manually ok, but I want the text to be at the start of the whole text when the controller loads.

How do I do that?

Bigdadda06
  • 45
  • 1
  • 1
  • 8

1 Answers1

4

You can set the contentOffset of your textView to programmatically scroll to the top:

textView.setContentOffset(.zero, animated: false)

Do it in your viewDidLayoutSubviews function, which is:

Called to notify the view controller that its view has just laid out its subviews.

override func viewDidLayoutSubviews() {
    textView.setContentOffset(.zero, animated: false)
}
Rashwan L
  • 38,237
  • 7
  • 103
  • 107