概述
- UIPageControl控件在程序中出現(xiàn)的?較頻繁,尤其在和UIScrollView(滾動視圖)配合來顯??量數(shù)據(jù)時松捉,會使?它來控制UIScrollView的翻頁夹界。在滾動ScrollView時可通過PageControl中的??點來觀察當前頁?的位置,也可通過點擊PageControl中的??點來滾動到指定的頁?隘世。
屬性和方法
初始化方法
UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 40, [UIScreen mainScreen].bounds.size.width, 40)];
設(shè)置小白點的個數(shù)
pageControl.numberOfPages = 10;
設(shè)置當前選中的點
pageControl.currentPage = 0;
設(shè)置當前選中的小白點的顏色
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
設(shè)置未選中小白點的顏色
pageControl.pageIndicatorTintColor = [UIColor greenColor];
用于控制是否只有一個頁面時隱藏頁面控件(默認值為NO
)
pageControl.hidesForSinglePage = YES;
設(shè)置此屬性的值可柿,YES
以便當用戶點擊控件以轉(zhuǎn)到新頁面時,類將延遲更新頁面控件丙者,直到它調(diào)用复斥。將該值設(shè)置為(缺省值)以立即更新頁面控件。
pageControl.defersCurrentPageDisplay = YES;
此方法更新頁面指示器械媒,以便當前頁面(白點)與從中返回的值匹配目锭。如果is
的值忽略這個方法评汰。設(shè)置值直接立即更新指標。
[pageControl updateCurrentPageDisplay];
添加點擊事件
[pageControl addTarget:self action:@selector(valueChanged:) forControlEvents:(UIControlEventValueChanged)];