I have created a scrolling pageviewcontroller but I can not get the dots/bar to show up. From my understanding, this should be present by default as long as Navigation is set to Horizontal and Transition style is set to Scroll, but nothing is showing.
I then added some additional code to add and style the dots, but still nothing. Here is my code as it stands now:
import UIKit
class Swipable_Images: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate{
var pages = [UIViewController]()
var pageControl = UIPageControl()
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.dataSource = self
configurePageControl()
let p1: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "stop1_image1")
let p2: UIViewController! = storyboard?.instantiateViewController(withIdentifier: "stop1_image2")
pages.append(p1)
pages.append(p2)
setViewControllers([p1], direction: UIPageViewController.NavigationDirection.forward, animated: false, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController)->UIViewController?{
let cur = pages.index(of: viewController)!
let prev = abs((cur - 1) % pages.count)
return pages[prev]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController)->UIViewController?{
let cur = pages.index(of: viewController)!
let nxt = abs((cur+1) % pages.count)
return pages[nxt]
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return pages.count
}
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool){
let pageContentViewController = pageViewController.viewControllers![0]
self.pageControl.currentPage = pages.index(of: pageContentViewController)!
}
//Swipe Indicator Bar
func configurePageControl(){
pageControl = UIPageControl(frame: CGRect(x: self.view.center.x, y: self.view.center.y, width: UIScreen.main.bounds.width, height: 50))
self.pageControl.numberOfPages = pages.count
self.pageControl.currentPage = 0
self.pageControl.tintColor = UIColor.black
self.pageControl.pageIndicatorTintColor = UIColor.white
self.pageControl.currentPageIndicatorTintColor = UIColor.black
self.view.addSubview(pageControl)
}
}
I even went ahead and created a new, blank page view controller to test with no code at all. I just set the Navigation to Horizontal and Transition to Scroll and nothing else. No code or fussing with it. I used a User Defined Runtime Attribute to set the background color to a random blue so that I would be able to see the nav/dot bar if it was there, but I'm still getting nothing.
What am I missing?