Objective-C Learning Notes - UIPageControl

UIPageControl

翻页控件

UIPageControl 控件在 iOS 应用程序中出现的比较频繁,尤其在和 UIScrollView 配合来显示大量数据.

创建:

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

设置属性:

myPageControl.numberOfPage = 5; //页面数目
myPageControl.currentPage = 3; //当前页数,第四页
myPageControl.hidesForSinglePage = YES; //隐藏指示器
myPageControl.defersCurrentPageDisplay = YES;
[myPageControl updateCurrentPageDisplay];

显示控件:

[self.view addSubView:myPageControl];

通知:

    当用户点击分页控件时,会触发一个 UIControlEventValueChanged 事件.可以用类 UIControl 中得 addTarget 方法为其指定一个动作,如下:

- (void)pageChange:(id)sender{
    UIPageControl *control = (UIPageControl *)sender;
    NSInteger page = control.currentPage;
    // add ur code here
}
[myPageControl addTarget:self action:@selector(pageChange:) forControlEvents: UIControlEventValueChanged];


标签:ios, object-c, uipagecontrol