UIScrollView scroll to bottom programmatically

nico picture nico · Jun 4, 2009 · Viewed 210.9k times · Source

How can I make a UIScrollView scroll to the bottom within my code? Or in a more generic way, to any point of a subview?

Answer

Ben Gotow picture Ben Gotow · Jun 4, 2009

You can use the UIScrollView's setContentOffset:animated: function to scroll to any part of the content view. Here's some code that would scroll to the bottom, assuming your scrollView is self.scrollView:

CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height + self.scrollView.contentInset.bottom);
[self.scrollView setContentOffset:bottomOffset animated:YES];

Hope that helps!