Use the button to manually scroll through the UIScrollView page

I have a UIScrollView that has 10 images from an array. I need to scroll left or right to the next or previous image using the button

button scrollview button < [ ... ] > 
+4
source share
2 answers

Well, here's how I was able to properly scroll through a UIScrollView using UIButton. The IF statements here ensure that scrollview does not go beyond My NSArray images.

 #pragma mark - #pragma mark Use a UIButton to scroll a UIScrollView Left or Right -(IBAction)scrollRight{ if(pos<9){pos +=1; [scrollView scrollRectToVisible:CGRectMake(pos*scrollView.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES]; NSLog(@"Position: %i",pos); } } -(IBAction)scrollLeft{ if(pos>0){pos -=1; [scrollView scrollRectToVisible:CGRectMake(pos*scrollView.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES]; NSLog(@"Position: %i",pos); } } 
+9
source

set the scrollable contentOffset property to change the scroll position.

+3
source

All Articles