Skip to content

Instantly share code, notes, and snippets.

@pnicholls
Created June 30, 2011 08:39
Show Gist options
  • Save pnicholls/1055870 to your computer and use it in GitHub Desktop.
Save pnicholls/1055870 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad
{
[self setupPage];
[super viewDidLoad];
}
#pragma mark -
#pragma mark The Guts
- (void)setupPage
{
scrollView.delegate = self;
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:@"image%d.png", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (image == nil) {
break;
}
CGRect myImageRect = CGRectMake(185.0f, 135.0f, 400.0f, 300.0f);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImageRect];
[imageView setImage:image];
[imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[imageView.layer setBorderWidth: 5.0];
imageView.opaque = YES; // explicitly opaque for performance
CGRect rect = imageView.frame;
rect.size.height = image.size.height;
rect.size.width = image.size.width;
rect.origin.x = ((scrollView.frame.size.width - image.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2);
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += scrollView.frame.size.width;
}
self.pageControl.numberOfPages = nimages;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment