28

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!

Daniel Kappacher
  • 472
  • 1
  • 6
  • 15

1 Answers1

46

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.

amq
  • 160
  • 4
  • 17
yjsoon
  • 829
  • 7
  • 18
  • 1
    Funnily enough, your question also helped me — I had that code in as boilerplate, and was wondering why there was a white strip at the bottom of my view. So thanks, too :) – yjsoon Mar 31 '13 at 07:29
  • 1
    Haha that's good to hear that it helped you too :) - do you know if you can change the color of the points? and how do I hide the black bar at the bottom? Is that possible? Thanks – Daniel Kappacher Mar 31 '13 at 12:14
  • 4
    just FYI UIPageViewController has to transition style set to scroll. Page curl doesn't show UIPageControl – kraag22 Nov 26 '14 at 10:23