新建singleview工程,名为MyScroll
在xib文件中加入scroll View和 page Control
添加四张相同的图片到工程里面去。scroll view选中paging Enabled属性。
修改viewDidLoad
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_scrollView.contentSize=CGSizeMake(320.*4,240.);
for (int i=1; i<=4; i++) {
UIImageView *imgView=[[[UIImageViewalloc]initWithImage:[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",i]]]autorelease];
imgView.frame=CGRectMake((i-1)*320.,0.,320., 240.);
[_scrollViewaddSubview:imgView];
}
}
这样就可以一页一页显示图片了。
源码地址:http://download.csdn.net/detail/cloud95/5187899