UIScrollView
(一般与滚动视图配合使用)
1.点的个数 numberOfPages 4
2.选中点的颜色 currentPageIndicatorTintColor UIColor orangeColor
3.点的背景颜色 pageIndicatorTintColor UIColor cyanColor
4.点击方法 addTarget: action: forControlEvents:
self @selector(pageAction:) UIControlEventValueChanged
5.创建UIPageControl
UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 600, 200, 40)];
page.backgroundColor = [UIColor redColor];
page.tag = 1000;
[self.view addSubview:page];
[page release];
//专门用来缩放的协议方法
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [scrollView.subviews firstObject];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//滑动图片,让圆点跟着一起动
UIPageControl *page = (UIPageControl *)[self.view viewWithTag:1000];
page.currentPage = self.scrollView.contentOffset.x / WIDTH;
}
-(void)pageAction:(UIPageControl *)page{
//点的个数从第0张开始计算
NSLog(@"%ld",page.currentPage);
//触发事件,进行图片的切换
[self.scrollView setContentOffset:CGPointMake(WIDTH * (page.currentPage), 0) animated:YES];
}