- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion]floatValue]>=7) {
self.automaticallyAdjustsScrollViewInsets=NO;
}
self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 400)];
self.scrollView.pagingEnabled=YES;
self.scrollView.delegate=self;
self.scrollView.showsHorizontalScrollIndicator=NO;
self.scrollView.showsVerticalScrollIndicator=NO;
[self.view addSubview:self.scrollView];
for (int i=0; i<6; i++) {
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, self.scrollView.frame.size.height)];
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"image%d",i]];
[self.scrollView addSubview:imageView];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
label.text=[NSString stringWithFormat:@"%d",i];
label.center=imageView.center;
[imageView addSubview:label];
}
[self.scrollView setContentSize:CGSizeMake(320*6, 400)];
[self.scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point=scrollView.contentOffset;
if ((int)point.x==0) {
[scrollView setContentOffset:CGPointMake(320*4, 0) animated:NO];
}else if ((int)point.x==320*5)
{
[scrollView setContentOffset:CGPointMake(320, 0) animated:NO];
}
}