UIPageViewController provides users the ability to easily transition between several views by using a swipe gesture. In order to create a UIPageViewController, you must implement the UIPageViewControllerDataSource methods. These include methods to return both the UIPageViewController before and after the current UIPageViewController along with the presentationCount and presentationIndex methods.
A simple way to create horizontal page view controllers ( infinite pages )
Let's create a new project, I'm choosing Single View Application for better demonstration
Drag a page view controller to the storyboard, there are 2 things you should change after that:
Set the page view controller as initial view controller
Change the transition style to scroll
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 :)
This is what the final project looks like, you get a view controller with different color with every scroll:
Create a horizontal paging UIPageViewController programatically
Init array of view controllers which will be managed by UIPageViewController. Add a base view controller class which has property identifier which will be used to identify view controllers when working with UIPageViewController data source methods. Let the view controllers to inherit from that base class.
Create UIPageViewController instance.
Data source is current class which must implement UIPageViewControllerDataSource protocol.
setViewControllers will add only first view controller, next will be added to the stack using data source methods
Add UIPageViewController as a child view controller so it will receive from it's parent view controller appearance and rotation events.