Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the UIPageControl created by iOS6 UIPageViewController?

I'm using a UIPageViewController with Navigation set to Horizontal, Transition Style set to Scroll (in InterfaceBuilder), and no spine. Which gives me a lovely UIPageControl integrated. Now I want to be able to toggle whether it's displaying (because there's artwork underneath it).

I've tried setting presentationCountForPageViewController and presentationIndexForPageViewController to return 0 when the UIPageControl is supposed to be hidden, but those methods aren't being called when I want.

Pausing for stacktrace, I see them being called by [UIPageViewController _updatePageControlViaDataSourceIfNecessary]...I assume my app would be rejected if I tried to use that method.

Should I hunt through subviews for it, or roll my own so I have control over it, or is there some better way to toggle its visibility?

Thanks!

like image 856
Kaolin Fire Avatar asked Dec 24 '12 00:12

Kaolin Fire


2 Answers

I would say, hunt through the subviews. This code successfully finds the UIPageControl in the subviews hierarchy:

NSArray *subviews = pageController.view.subviews;
UIPageControl *thisControl = nil;
for (int i=0; i<[subviews count]; i++) {
    if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
        thisControl = (UIPageControl *)[subviews objectAtIndex:i];
    }
}

I'm using this to customize the color of the dots, I imagine you could do the same with the alpha value or send it to the back or something.

Apple provides no direct interface to the UIPageControl through the UIPageViewController class, but there are no illegal method calls required in order to get to it... I don't see why this would result in an app rejection.

like image 151
felixthecat Avatar answered Sep 21 '22 01:09

felixthecat


You can access this for all PageControl objects by using appearance (see the UIAppearance protocol), but to get a specific instance you'd have to use recursion. Swift code:

let pageControl = UIPageControl.appearance()
like image 25
Dan Rosenstark Avatar answered Sep 21 '22 01:09

Dan Rosenstark