Loading

UIPageControl简单使用

1.添加一个UIPageControl到view中

 1 -(void)addPageControl
 2 {
 3     UIPageControl* page=[[UIPageControl alloc]init];
 4     page.center=CGPointMake(WBScreenWidth*0.5, WBScreenHeight*0.9);
 5     //设置小圆点的总数
 6     page.numberOfPages=ImageCount;
 7     //当前高亮的是哪一个
 8     page.currentPage=0;
 9     //设置高亮的颜色
10     page.currentPageIndicatorTintColor=[UIColor orangeColor];
11     //设置其它非高亮的普通颜色
12     page.pageIndicatorTintColor=[UIColor grayColor];
13     
14     _myPage=page;
15     [self.view addSubview:page];
16 }

 

2.实现UIScrollView的代理方法,监听滚动

1 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
2 {
3     // 获取当前的偏移量,计算当前第几页
4     int pageNum = 0.5 + (scrollView.contentOffset.x/WBScreenWidth) ;
5     
6     // 设置页数
7     self.myPage.currentPage=pageNum;
8 }

 

posted @ 2015-10-28 23:30  yaro-feng  阅读(519)  评论(0编辑  收藏  举报