一、
- (void)viewDidLoad {
[super viewDidLoad];
//UIPageControl翻页指示器 继承自UIControl 驱动型控件(注册点击事件)
UIPageControl *pageCon = [[UIPageControl alloc]initWithFrame:CGRectMake(10, 450, 300, 30)];
pageCon.backgroundColor = [UIColor cyanColor];
pageCon.userInteractionEnabled = YES;
//1、设置页数/点数
pageCon.numberOfPages = 10;
//2、设置当前页数 默认是0
pageCon.currentPage = 5;
//3、单页时是否隐藏
pageCon.hidesForSinglePage = YES;
//4、当前点得颜色
pageCon.currentPageIndicatorTintColor = [UIColor redColor];
//5、未选中的点得颜色
pageCon.pageIndicatorTintColor = [UIColor greenColor];
//6、pageControl是否可以被点击
pageCon.enabled = YES;
[self.view addSubview:pageCon];
//添加点击事件
[pageCon addTarget:self
action:@selector(controlCliked:)
forControlEvents:UIControlEventTouchUpInside];
}
二、
#pragma mark -UIControl Method
- (void)controlCliked:(UIControl*)control{
//点击时点击左右两边 会自动切换 而不是点击小圆点
NSLog(@"点击了pageController");
}