/* Some sample code for a horizontal paged UIScrollView with a gap between each image (which looks nicer). Note - not using contentInset, we want each page to fill the iPhone screen and the gap only to be visible when scrolling (like Photos.app). Taking the iPhone status bar into account - our viewport is 320x460 Our UIScrollView is therefore set in Interface Builder to 340x460 with a -10 X offset (so it's larger than the viewport but still centred) Then we do the following... */ // Our image filenames NSArray *imgNames = [[NSArray alloc] initWithObjects:@"0.jpg", @"1.jpg", @"2.gif", @"3.jpg", @"4.jpg", @"5.png", @"6.jpg", @"7.jpg", @"8.jpg", @"9.png", @"10.jpg", nil]; // Setup the array of UIImageViews imgArray = [[NSMutableArray alloc] init]; UIImageView *tempImageView; for(NSString *name in imgNames) { tempImageView = [[UIImageView alloc] init]; tempImageView.contentMode = UIViewContentModeScaleAspectFit; tempImageView.image = [UIImage imageNamed:name]; [imgArray addObject:tempImageView]; [tempImageView release]; } CGSize pageSize = scrollView.frame.size; // scrollView is an IBOutlet for our UIScrollView NSUInteger page = 0; for(UIView *view in imgArray) { [scrollView addSubview:view]; // This is the important line view.frame = CGRectMake(pageSize.width * page++ + 10, 0, pageSize.width - 20, pageSize.height); // We're making use of the scrollView's frame size (pageSize) so we need to; // +10 to left offset of image pos (1/2 the gap) // -20 for UIImageView's width (to leave 10 gap at left and right) } scrollView.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height);