UIPageViewController with PageControl

Daniel Kappacher picture Daniel Kappacher · Mar 28, 2013 · Viewed 17.1k times · Source

I'm using a UIPageViewController to display 4 other ViewControllers. So my RootViewController is a PageViewController which displays 4 other ViewControllers I created in my Storyboard with segues to different Views . All works perfect. But is it possible to add an UIPageControl to this PageViewController. Is this possible anyhow?

Or has someone an idea how I can achieve a similar result?

Would be great, thanks!

Answer

yjsoon picture yjsoon · Mar 30, 2013

You need to implement these UIPageViewControllerDataSource methods:

Swift

func presentationCount(for pageViewController: UIPageViewController) -> Int { ... }
func presentationIndex(for pageViewController: UIPageViewController) -> Int { ... }

Obj-C

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController

And you'll get a page control showing up at the bottom 36px of your UIPageViewController. Try changing the color of the view to a dark color, if you can't see them.