Hide UIPageControl UIPageControlViewController at specific page index
I want to hide the page control indicator on a specific VC and instead show a button with the text "Get started". However, the user can still return to managing the page.
I've tried this:
self.pageController = [UIPageControl appearance];
self.pageController.pageIndicatorTintColor = [UIColor redColor];
self.pageController.currentPageIndicatorTintColor = [UIColor greenColor];
if(self.pageIndex == 1){
self.pageController.hidden = YES;
NSLog(@"hide you!");
}
However, this doesn't work. install self.pageController.hidden = YES
without if statement and also starts nslog. It seems like somehow this can only be set once.
I also don't know how smooth it will be. I obviously don't want it to change when the user fully arrives on the page itself, but in transition to it.
What is the best way to solve this problem?
source to share
If you want to use the space that the UIPageControl is in, you can change the view frame so the page control leaves the screen:
func togglePageControl(visible: Bool) {
if let pageVC = parent as? UIPageViewController {
// find UIPageControl
for case let control in pageVC.view.subviews where control is UIPageControl {
let height = control.frame.height
if visible {
pageVC.view.frame.size.height -= height
} else {
pageVC.view.frame.size.height += height
}
break
}
}
}
Use it in the UIViewController you want with a hidden page control (checking for visibility is because viewWillAppear is called even when the user starts to navigate to another screen and then interrupts that action):
var isPageControlVisible = true
override func viewWillAppear(_ animated: Bool) {
if isPageControlVisible {
togglePageControl(visible: false)
isPageControlVisible = false
}
}
override func viewDidDisappear(_ animated: Bool) {
togglePageControl(visible: true)
isPageControlVisible = true
}
source to share