And you need to create a UIPageViewController class, then set it as custom class of the page view controller on the storyboard
Paste this code into your UIPageViewController class, you should get a colorful infinite paged app :)
class PageViewController: UIPageViewController, UIPageViewControllerDataSource {
override func viewDidLoad() {
self.dataSource = self
let controller = createViewController()
self.setViewControllers([controller], direction: .forward, animated: false, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let controller = createViewController()
return controller
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let controller = createViewController()
return controller
}
func createViewController() -> UIViewController {
var randomColor: UIColor {
return UIColor(hue: CGFloat(arc4random_uniform(360))/360, saturation: 0.5, brightness: 0.8, alpha: 1)
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "View Controller")
controller.view.backgroundColor = randomColor
return controller
}
}
This is what the final project looks like, you get a view controller with different color with every scroll: