UIPageControl配合UIScrollView使用
self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
self.scrollView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:self.scrollView];
self.scrollView.delegate = self;
[_scrollView release];
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.contentSize = CGSizeMake(WIDTH * 7, HEIGHT);
for (NSInteger i = 1; i < 8; i++) {
NSString *picName = [NSString stringWithFormat:@"h%ld.jpeg",i];
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:picName]];
imageView.frame = CGRectMake(WIDTH * (i - 1), 0, WIDTH, HEIGHT);
[self.scrollView addSubview:imageView];
[imageView release];
}
self.scrollView.pagingEnabled = YES;
UIPageControl *page = [[UIPageControl alloc]initWithFrame:CGRectMake(100, 635, 200, 40)];
[self.view addSubview:page];
self.scrollView.maximumZoomScale = 2;
self.scrollView.minimumZoomScale = 0.5;
self.scrollView.zoomScale = 1;
page.tag = 1000;
[page release];
page.numberOfPages = 7;
page.pageIndicatorTintColor = [UIColor grayColor];
page.currentPageIndicatorTintColor = [UIColor purpleColor];
[page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
self.LTview = [[LTView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
self.LTview.lable.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.LTview];
[self.LTview release];
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSInteger i = scrollView.contentOffset.x / WIDTH;
UIPageControl *page = (UIPageControl *)[self.view viewWithTag:1000];
page.currentPage = i;
}
-(void)pageAction:(UIPageControl *)page{
NSLog(@"%ld",page.currentPage);
[self.scrollView setContentOffset:CGPointMake(WIDTH * page.currentPage, 0) animated:YES];
}
#pragma mark 专门用来缩放的协议方法
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [scrollView.subviews firstObject];
}