2014年6月7日 星期六

IOS Custom Page Control

How To Create UIPageViewController Using Storyboard

今天剛好在玩UIPageViewController,看到兩個不錯的功能
1. 只要實作以下兩個method,PageControll就會生出來
2. 但是 PageControll 被 UIPageViewController 藏得死死低,所以有另外一種方式把PageControll 做 Customize

To display a page indicator, you have to tell iOS the number of pages (i.e. dots) to display in the page view controller and which page must be selected at the beginning. Add the following two methods at the end of the ViewController.m file:

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
    return [self.pageTitles count];
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
    return 0;
}

Customize the Page Indicator

If you compile and run the app now, your app should run properly but you may find the page indicator missing. Actually the page indicator is there but the color of the dots is the same as the color of the view. So let’s change its color.
In the AppDelegate.m, add the following lines of code in the didFinishLaunchingWithOptions: method:

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
How do I make the bottom bar with dots of a UIPageViewController translucent?

沒有留言:

張貼留言