Last active
August 29, 2015 14:04
-
-
Save bimawa/b8721a64316cc96f70ca to your computer and use it in GitHub Desktop.
Create Pagin scroll indicator with scroll effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
_pageControl = [[UIPageControl alloc] init]; | |
[self.pageControl setCurrentPage:0]; | |
[self.pageControl setNumberOfPages:6]; | |
[self.pageControl addTarget:self action:@selector(a_changedPageControl:) forControlEvents:UIControlEventValueChanged]; | |
[self.view addSubview:self.pageControl]; | |
[self.scrollView setPagingEnabled:YES]; | |
[self.scrollView setDelegate:self]; | |
[self.scrollView setShowsHorizontalScrollIndicator:NO]; | |
[self.scrollView setShowsVerticalScrollIndicator:NO]; | |
[self.view addSubview:self.scrollView]; | |
} | |
#pragma mark - UIScrollViewDelegate | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView | |
{ | |
int pageNum = scrollView.contentOffset.x / scrollView.frame.size.width; | |
[self.pageControl setCurrentPage:pageNum]; | |
} | |
- (void)a_changedPageControl:(UIPageControl *)pageControl | |
{ | |
int currentPage = [pageControl currentPage]; | |
CGRect rectFoPosition = CGRectMake(self.scrollView.bounds.size.width * currentPage, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height); | |
[self.scrollView scrollRectToVisible:rectFoPosition animated:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment