您的位置:首页 > 产品设计 > UI/UE

UIPageControl分页控件

2015-11-04 14:02 447 查看
要使用滚动视图的分页效果,通常会配合UIPageControl分页控制控件,以增强分页效果

该控件的常用属性 如下:


相关的代码:

//分页控制控件

_pageControl = [[UIPageControlalloc]init];

//设置大小

_pageControl.bounds =CGRectMake(0,0,
150.0, 50.0);

//设置位置

_pageControl.center =CGPointMake(scrollView.frame.size.width/2,
scrollView.frame.size.height-50);

//总页数

[_pageControlsetNumberOfPages:2];

//当前页面

[_pageControlsetCurrentPage:0];

//设置其他页面小圆点的颜色

[_pageControlsetPageIndicatorTintColor:[UIColorwhiteColor]];

[_pageControlsetCurrentPageIndicatorTintColor:[UIColorredColor]];

[self.viewaddSubview:_pageControl];

}

#pragma mark 代理方法实现

/**

* 如果偏移量横坐标超过scrollView的宽就切到第二页
如果没有就切换到第一页

* 页面在滚动时一直在调用

* @param scrollView <#scrollView description#>

*/

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

// if (scrollView.contentOffset.x<50) {

// _pageControl.currentPage = 0;

// }else if(scrollView.contentOffset.x>50){

// _pageControl.currentPage = 1;

// }

//

// }

/**

* 完成减速意味着切换完成

*

* @param scrollView <#scrollView description#>

*/

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

if (scrollView.contentOffset.x<50) {

_pageControl.currentPage =0;

}else if(scrollView.contentOffset.x>50){

_pageControl.currentPage =1;

}

}

//#pragma mark 代理方法的实现

///**

// * 返回值就是要缩放的视图对象

// *

// * @param scrollView <#scrollView description#>

// *

// * @return <#return value description#>

// */

//- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

// return _canyonView;

//}
其中需要注意的是 如果成员变量的名字改了 但是你不想更改那么多的名字 可以这么做 定义成员变量 UIPageControl *pager;然后将之前定义的page赋值给pager
也就是 _pager = page;这样在代理方法里就能用到page而无需更改很多名字了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: