How to programmatically set the current page for UIPageControl?

I have 3 "pages" (page 0, page 1, page 2) in a UIScrollView to which I snap with my fingers. There is also a UIPageControl. UIScrollView starts by presenting page 0. What I want to do is sometimes present page 3 FIRST. How can I do this programmatically.

Simply setting currentPage (from UIPageControl) to the page number, by the way, does nothing.

+6
iphone xcode uiviewcontroller uiscrollview uipagecontrol
source share
1 answer

(from the PageControl example)

To go directly to a specific scrollView section, use

CGRect frame = scrollView.frame; frame.origin.x = frame.size.width * page; frame.origin.y = 0; [scrollView scrollRectToVisible:frame animated:YES]; 

I just implemented the same thing, for example scrollview and page control, and used

 pageControl.currentPage = {pageNumber}; 

which worked fine, you are sure that the pageControl output window is correctly configured in Interface Builder (if you use it).

If the problem is that scrollView is not working, not on the Control page. Then make sure the scroll content is set correctly.

  scrollView.contentSize = CGSizeMake(320*numberOfPages, scrollView.frame.size.height); 

For this scroll, you add content to each section

 page1ViewController.view.frame = CGRectMake(0, 0, 320, 200); [scrollView addSubview:page1ViewController.view]; 

The next page is pressed at 1 screen width

 page2ViewController.view.frame = CGRectMake(320, 0, 320, 200); [scrollView addSubview:page2ViewController.view]; 
+23
source share

All Articles