8

I would like to utilise UIPageViewController to paginate through my datasource. Essentially it works, however I don't get to see the dots as an indication on which page I am.

Someone has asked this question before and I have done exactly what the answer suggested. However I still don't get any dots on the bottom of my screen.

Essentially I am using UIPageViewControllerTransitionStyleScroll and navigation orientation is UIPageViewControllerNavigationOrientationHorizontal.

I have created a sample project on GitHub to demonstrate the problem.

If anyone would be so kind and help out.

Community
  • 1
  • 1
Houman
  • 64,245
  • 87
  • 278
  • 460

3 Answers3

39

Another way to fix this issue is to customize the page control's tint colors:

UIPageControl *pageControlAppearance = [UIPageControl appearanceWhenContainedIn:[UIPageViewController class], nil];
pageControlAppearance.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControlAppearance.currentPageIndicatorTintColor = [UIColor darkGrayColor];
Community
  • 1
  • 1
Senseful
  • 86,719
  • 67
  • 308
  • 465
19

Update: Please see the answer by @Senseful below. It is preferred over this one.

Original Answer: I checked out your project, and the reason you can't see the UIPageController (the dots) is because its default color is white, and the UIPageViewController's view's superview is white. To solve this you could change the color of the background or change the color of the UIPageController.

To change the background color to a non-white color, in -viewDidLoad: in FTAdviceViewController.m the set the background color of the view that contains the UIPageViewController's view.

-(void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    ...
}

To change the color of the dots, get the UIPageViewController's UIPageControl subview after you've created the UIPageViewController. You can then alter its pageIndicatorTintColor, currentPageIndicatorTintColor, and backgroundColor properties.

- (void)viewDidLoad
{
    ...
    // after creating the UIPageViewController
    for (UIView *subview in self.pageController.view.subviews) {
        if ([subview isKindOfClass:[UIPageControl class]]) {
            UIPageControl *pageControl = (UIPageControl *)subview;
            pageControl.pageIndicatorTintColor = [UIColor yellowColor];
            pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
            pageControl.backgroundColor = [UIColor blueColor];
        }
    }
}
Joseph Chen
  • 1,520
  • 13
  • 21
  • Thanks Joseph. I didn't expect it to be in white colour. Considering iOS 7 is by default white with blue tint, its crazy that they chose the white colour for `UIPageControl`. – Houman Jan 23 '14 at 10:24
  • 1
    My pleasure :) This had me boggled too when I first encountered it. – Joseph Chen Jan 23 '14 at 10:52
  • OMG how dumb do I feel? Thanks for this, it saved me a lot of time. – John G May 05 '15 at 20:16
0

I answered a previous SO question with this block I used in my own Swift 4 project.

    override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    for view in self.view.subviews{
        if view is UIPageControl{
            (view as! UIPageControl).currentPageIndicatorTintColor = .yellow
            }
        }
    }

You have the UIPageControl in this block, so you can customize it as much as you want.

wsgeorge
  • 1,928
  • 17
  • 20