Skip to content

Instantly share code, notes, and snippets.

@mwhuss
Created January 13, 2013 18:42
Show Gist options
  • Save mwhuss/4525626 to your computer and use it in GitHub Desktop.
Save mwhuss/4525626 to your computer and use it in GitHub Desktop.
Paging Scroll View
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