How do you combine UIScrollview with UIPagecontrol to display different views?

I searched and searched for a tutorial for this, but none of them are what I am looking for. I tried an Apple sample, but these are just colors, and I don’t know how to make it look. All I'm looking for is a screen on which the page will be displayed, showing page control. Every time a scroll view page, I want it to show a completely different view. Not other text or images, but a different presentation. Very similar to the home screen of an iPhone or ESPN Scorecenter application. Please help! Thank.

+9
iphone uiscrollview uipagecontrol
Aug 20 '10 at 16:52
source share
5 answers

I created this universal solution, since the examples found were complex, and it is accessible to me, the code should be clear.

- (IBAction)changePage:(id)sender { _pageControlUsed = YES; CGFloat pageWidth = _scrollView.contentSize.width /_pageControl.numberOfPages; CGFloat x = _pageControl.currentPage * pageWidth; [_scrollView scrollRectToVisible:CGRectMake(x, 0, pageWidth, _scrollView.frame.size.height) animated:YES]; } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { _pageControlUsed = NO; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { if (!_pageControlUsed) _pageControl.currentPage = lround(_scrollView.contentOffset.x / (_scrollView.contentSize.width / _pageControl.numberOfPages)); } 
+16
Jan 09 '13 at 8:04 on
source share

This does the same as @ReneDohan, without requiring a variable to hold state

 - (IBAction)changePage:(id)sender { CGFloat x = self.pageControl.currentPage * self.scrollView.frame.size.width; [self.scrollView setContentOffset:CGPointMake(x, 0) animated:YES]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.isDragging || scrollView.isDecelerating){ self.pageControl.currentPage = lround(self.scrollView.contentOffset.x / (self.scrollView.contentSize.width / self.pageControl.numberOfPages)); } } 
+14
Feb 06 '14 at 20:53
source share

Try this framework: https://github.com/AdrianFlorian/AFImageViewer to present images in scroll mode using the page control to indicate the current page.

I have not added documentation yet, but you can see examples if you are cloning a project.

You can easily: - upload images from the Internet to a separate stream, providing only an array of URLs (image URLs) - give it an array of UIImage objects - implement a delegate and independently manage the image for each page

+4
May 11 '12 at 20:19
source share

There is a related question: How to use UIPageControl to create multiple views? A really good way to do this is explained in this blog post: http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html .

+1
Oct 05 2018-10-10
source share

I did a demo project for this question. Please visit: https://github.com/lenhhoxung86/PageControlDemo

+1
Mar 20 '14 at 8:44
source share



All Articles