Created
May 7, 2012 08:39
-
-
Save Lejdborg/2626688 to your computer and use it in GitHub Desktop.
Updated UIPageControl for paged UIScrollView
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
/** | |
* Set the UIScrollView's delegate to self, and set self's protocol to UIScrollViewDelegate. | |
* | |
* This works with a horizontally paged scroll view but can be easily converted to vertical, | |
* just switch all "width" to "height". | |
*/ | |
- (void)scrollViewDidScroll:(UIScrollView *)sender { | |
// Switch the indicator when more than 50% of the previous/next page is visible | |
CGFloat pageWidth = _scrollView.frame.size.width; | |
int currentPage = ceil((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth); | |
_pageControl.currentPage = currentPage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment