Skip to content

Instantly share code, notes, and snippets.

@bleft
Created July 4, 2013 11:12
Show Gist options
  • Save bleft/5926865 to your computer and use it in GitHub Desktop.
Save bleft/5926865 to your computer and use it in GitHub Desktop.
UIScrollView and UIPageControl set Page scrollView, set Page on Page controller
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