Skip to content

Instantly share code, notes, and snippets.

@mr5z
Created February 18, 2016 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/c22746ecee1ae2d53244 to your computer and use it in GitHub Desktop.
Save mr5z/c22746ecee1ae2d53244 to your computer and use it in GitHub Desktop.
UIScrollView as a page container and UIViewController as pages
- (void)viewDidLoad {
[super viewDidLoad];
int pageCount = 2;
// int pageWidth = self.view.frame.size.width;
// int pageHeight = self.view.frame.size.height;
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
for(int i = 0;i < pageCount; ++i) {
UIViewController *page = [storyBoard
instantiateViewControllerWithIdentifier:
[NSString stringWithFormat:@"vcPage%d", (i + 1)]];
// CGRect pageSize = CGRectMake(i * pageWidth, 0, pageWidth, pageHeight);
// TourPageView *page = [[TourPageView alloc] initWithFrame:pageSize];
[mScrollView addSubview:page.view];
}
mScrollView.contentSize = CGSizeMake(
mScrollView.frame.size.width * pageCount,
mScrollView.frame.size.height);
mScrollView.delegate = self;
mPageControl.numberOfPages = pageCount;
[mPageControl addTarget:self
action:@selector(didPressPageController:)
forControlEvents:UIControlEventTouchUpInside];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment