Reputation: 29
-- XCODE 5, iOS 7 --
I want to create an instruction manual for my application with 7 pictures sized 280 x 342, with a UIPageControl with 7 dots below it. I want to have it so the user swipes to the right and it navigates through the images i've made, showing the user how to play my game.
I've been searching for hours and can't find anything, I even tried asking on here already but wasn't given much help.
If anyone could direct me to a tutorial that explains how to do this, or write out the code and show me it would be much appreciated.
Thanks.
Upvotes: 1
Views: 642
Reputation: 6211
Ballpark:
-(void)setupPagingScrollView
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,280,342)];
[self addSubview:scrollView];
[scrollView setDelegate:self]
[scrollView setPagingEnabled:YES];
control = [[UIPageControl alloc] initWithFrame:yourPagingButtonsFrame];
[control setNumberOfPages:[imagePanes count]];
[self addSubview:control];
}
-(void)scrollViewDidScroll:(UIScrollView *)inScrollView
{
UIPageControl *control;
int currentPage = inScrollView.contentOffset.x / inScrollView.bounds.size.width;
[control setCurrentPage:currentPage];
}
You need to create a scrollview with paging enabled (this is what you will add your images to). Then you need to create a UIPageControl. Then when the scrollview scrolls (or when the scrollview ends scrolling, your choice there) you change the UIControl's page number based on the scroll position.
You can also set the UIPageControl's delegate to yourself so that you can listen for tab button clicks from it and adjust your scrollview accordingly, but I use it as a display of information only, not to receive user input.
Upvotes: 1
Reputation: 3864
Put the images side by side in a scrollview. Put a UIPageControl on top and set the number of pages to 7. Then use
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageWidth = scrollView.bounds.size.width;
NSInteger pageNumber = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = pageNumber;
}
Upvotes: 0