常用屬性和方法
// 共有幾個分頁“圓圈”
@property(nonatomic) NSInteger numberOfPages;
// 顯示當前的頁
@property(nonatomic) NSInteger currentPage;
// 只存在一頁時,是否隱藏,默認爲YES
@property(nonatomic) BOOL hidesForSinglePage;
// 刷新視圖
- (void)updateCurrentPageDisplay;
project: UIPageControlDemo
打開 AppDelegate.m
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中的 [self.window makeKeyAndVisible]; 頂上加入
UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 100, 320, 40)];
pageControl.backgroundColor = [UIColor grayColor];
[self.window addSubview:pageControl];
運行
在 UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 100, 320, 40)]; 下面加入
pageControl.numberOfPages = 10;
pageControl.currentPage = 2;
運行
可以點擊 左右移動
在 pageControl.currentPage = 2; 下面加入
pageControl.enabled = NO;
運行
將 pageControl.enabled = NO; 註釋掉加入
[pageControl addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
在加入方法
- (void)change:(UIPageControl *)pageControl
{
NSLog(@"index : %d", pageControl.currentPage);
}
運行
將
pageControl.numberOfPages = 10;
pageControl.currentPage = 2;
改爲
pageControl.numberOfPages = 1;
pageControl.hidesForSinglePage = YES;//如果是單頁就隱藏掉
運行
在真正項目開發時候都是 自定義該控件 因爲本身顯示的小點太小不方便操作