iOS控件之UIPageControl

作用:通常與UIScrollView連用,提示用戶當前顯示的頁數


常用屬性和方法


// 共有幾個分頁“圓圈”
@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;//如果是單頁就隱藏掉


運行

         在真正項目開發時候都是 自定義該控件 因爲本身顯示的小點太小不方便操作


發佈了91 篇原創文章 · 獲贊 5 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章