Skip to content

Instantly share code, notes, and snippets.

@iggym
Forked from mwhuss/PagingScrollView.mm
Created April 26, 2013 21:04
Show Gist options
  • Save iggym/5470450 to your computer and use it in GitHub Desktop.
Save iggym/5470450 to your computer and use it in GitHub Desktop.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
[self.view addSubview:scrollView];
NSArray *images = @[@"image1", @"image2", @"image3"];
[images enumerateObjectsUsingBlock:^(NSString *imageName, NSUInteger idx, BOOL *stop) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
imageView.frame = CGRectMake(idx * CGRectGetWidth(self.view.bounds), 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
[self.scrollView addSubview:imageView];
}];
self.scrollView.contentSize = CGSizeMake([images count] * CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment