Created
July 4, 2013 11:12
-
-
Save bleft/5926865 to your computer and use it in GitHub Desktop.
UIScrollView and UIPageControl set Page scrollView, set Page on Page controller
This file contains hidden or 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
static CGSize scrollSize; // set on viewDidLoad | |
- (CGRect)frameForPosition:(int)pos | |
{ | |
float x = pos * scrollSize.width; | |
float y = 0; | |
float width = scrollSize.width; | |
float height = scrollSize.height; | |
return CGRectMake (x, y, width, height); | |
} | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { | |
CGFloat pageWidth = scrollSize.width; | |
float fractionalPage = self.scrollView.contentOffset.x / pageWidth; | |
NSInteger page = lround(fractionalPage); | |
self.pageControl.currentPage = page; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment