UIPageControl 分页

UIPageControl* myPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0.0, 400.0, 320.0, 0.0)]; //


   属性设置

 

myPageControl.numberOfPages =5;

默认第一页会被选中。如果要选择其他页,可以设置currentPage 属性。页面索引从 0 开始:

myPageControl.currentPage =3;// 当前页数,第四页

默认情况下,即使只有一个页面,指示器也会显示进来。如果要在仅有一个页面的情况下隐藏指示器,可以将 hideForSinglePage 的值设为 YES。

myPageControl.hidesForSinglePage=YES;

如果你希望直到有时间执行完你的操作之后,才更新当前指示器当前指示页,可以将 defersCurrentPageDisPlay 设为YES。这样的话你必须调用控件的 updateCurentPageDisPlay 来更新当前页:

myPageControl.defersCurrentPageDisplay = YES; 
    [myPageControl updateCurrentPageDisplay];


当用户点触分页控件时,会产生一个 UIControlEventVakueChanged 事件。你可以用UIControl 类的 addTarget 方法,为其指定一个动作


-(void)pageChanged:(id)sender{ 
    UIPageControl* control = (UIPageControl*)sender; 
    NSInteger page = control.currentPage; 
    //添加你要处理的代码 
} 
         
[myPageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];

















 

你可能感兴趣的:(UIPageControl)