Skip to content

Instantly share code, notes, and snippets.

@pnicholls
Created June 30, 2011 12:34
Show Gist options
  • Save pnicholls/1056131 to your computer and use it in GitHub Desktop.
Save pnicholls/1056131 to your computer and use it in GitHub Desktop.
//
// WallrViewController.m
// Wallr
//
// Created by Peter Nicholls on 30/06/11.
// Copyright 2011 NA. All rights reserved.
//
#import "WallrViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation WallrViewController
@synthesize scrollView;
@synthesize pageControl;
#pragma mark -
#pragma mark UIView boilerplate
- (void)viewDidLoad
{
[self setupPage];
[super viewDidLoad];
}
- (void)setupPage
{
scrollView.delegate = self;
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSMutableArray *images = [[NSMutableArray alloc] init];
[images addObject:[UIImage imageNamed:@"image1.png"]];
[images addObject:[UIImage imageNamed:@"image2.png"]];
[images addObject:[UIImage imageNamed:@"image3.jpg"]];
[images addObject:[UIImage imageNamed:@"image4.png"]];
[images addObject:[UIImage imageNamed:@"image1.png"]];
[images addObject:[UIImage imageNamed:@"image2.png"]];
[images addObject:[UIImage imageNamed:@"image3.jpg"]];
[images addObject:[UIImage imageNamed:@"image4.png"]];
NSUInteger nimages = images.count;
CGFloat cx = 0;
for (UIImage *image in images) {
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.layer.shadowColor = [UIColor grayColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.layer.shadowRadius = 1.0;
imageView.opaque = YES; // explicitly opaque for performance
CGRect rect = imageView.frame;
rect.origin.x = 185.0f + cx;
rect.origin.y = 135.0f;
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
CGRect myImageRect2 = CGRectMake(185.0f, 535.0f, 400.0f, 300.0f);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImageRect2];
[imageView2 setImage:image];
[imageView2.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[imageView2.layer setBorderWidth: 5.0];
imageView2.layer.shadowColor = [UIColor grayColor].CGColor;
imageView2.layer.shadowOffset = CGSizeMake(0, 1);
imageView2.layer.shadowOpacity = 1;
imageView2.layer.shadowRadius = 1.0;
imageView2.opaque = YES; // explicitly opaque for performance
CGRect rect2 = imageView2.frame;
rect2.origin.x = 185.0f + cx;
rect2.origin.y = 535.0f;
imageView2.frame = rect2;
[scrollView addSubview:imageView2];
[imageView2 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