I have a scroll view which switches between two views. The two views are set up in viewDidLoad. I want to have a page control that switches when the according view is selected.
All tutorials I have looked at have been far to complex.
- (void)viewDidLoad {
[super viewDidLoad];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
CGRect pageFrame = CGRectMake(0, 0, scrollView.bounds.size.width, scrollView.bounds.size.height);
scrollView.contentSize = CGSizeMake(pageFrame.size.width * 2, pageFrame.size.height);
scrollView.pagingEnabled = YES;
view1.frame = pageFrame;
[scrollView addSubview:view1];
pageFrame.origin.x += pageFrame.size.width;
view2.frame = pageFrame;
[scrollView addSubview:view2];
}
- (IBAction)changePage:(id)sender {
}
When a user taps a page control to move to the next or previous page, the control sends the UIControlEventValueChanged event for handling by the delegate. The delegate can then evaluate the currentPage property to determine the page to display. The page control advances only one page in either direction.
Set the delegate of the page control for the ValueChanged action the changePage method of your controller.