0

I'm trying to get a UIScrollView to scroll upwards instead of downwards.I have everything set up except I don't know what line I should use to accomplish this. What should I do?

Niall

Niall Kehoe
  • 379
  • 2
  • 5
  • 18

1 Answers1

1

What I think you mean by this is that you want a scrollView that starts at the bottom and your content can be accessed by scrolling up.

In this case you simply need to figure out how large your content is, and set the setContentOffset of your scrollView to the height of your content:

override func viewDidLoad() {
    // other code here...

    // set the contentSize of the scrollView somewhere in here...

    // get the offset based on the size of the content
    let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
    // do not animate because we want to immediately scroll to the bottom
    scrollView.setContentOffset(bottomOffset, animated: false)

This code is adapted from this answer.

Community
  • 1
  • 1
Forest Kunecke
  • 2,160
  • 15
  • 32