Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page indication is missing in UIPageViewController

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.

like image 314
Houman Avatar asked Jan 23 '14 00:01

Houman


2 Answers

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];
like image 156
Senseful Avatar answered Oct 23 '22 15:10

Senseful


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];
        }
    }
}
like image 40
Joseph Chen Avatar answered Oct 23 '22 13:10

Joseph Chen