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.
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];
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];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With