imageView切换

// Create the scroll view and set its content size and delegate


UIScrollView *sv = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, BASEHEIGHT)] autorelease];


sv.contentSize = CGSizeMake(NPAGES * 320.0f, sv.frame.size.height);

sv.pagingEnabled = YES;

sv.delegate = self;

// Load in all the pages

for (int i = 0; i < NPAGES; i++)
{
NSString *filename = [NSString stringWithFormat:@"image%d.png", i+1];

UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:filename]];
iv.frame = CGRectMake(i * 320.0f, 0.0f, 320.0f, BASEHEIGHT);
[sv addSubview:iv];
[iv release];

}
[self.view addSubview:sv];

转载于:https://my.oschina.net/zhangzhihao/blog/91032

你可能感兴趣的:(imageView切换)