Can we customize the page indicator in UIPageViewController?

后端 未结 11 2007
广开言路
广开言路 2020-12-07 17:30

Now it\'s white dots with black background. What about if I want it to be black dots with white backgrounds?

- (NSInteger)presentationCountForPageViewControl         


        
11条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 18:15

    You can actually grab it and store it locally in your own property in one of the delegate calls.

    Put this code inside your delegate to access the UIPageControl inside the UIPageViewController:

    - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
    {
        [self setupPageControlAppearance];
        return kPageCount;
    }
    
    - (void)setupPageControlAppearance
    {
        UIPageControl * pageControl = [[self.view.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(class = %@)", [UIPageControl class]]] lastObject];
        pageControl.pageIndicatorTintColor = [UIColor grayColor];
        pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    }
    

提交回复
热议问题