Search code examples
iosios7uipageviewcontroller

Horizontal padding between UIPageViewController child view controllers


I am using UIPageViewController to display images that are embedded in child view controllers.

NSDictionary *options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey];
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options: options];
self.pageViewController.dataSource = self;
self.pageViewController.view.frame = self.view.bounds;

ImageViewController *initialViewController = [self viewControllerAtIndex:0];
initialViewController.index = 0;

NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];

Everything works great but I hate that the child view controllers are right next to one another.

enter image description here

I was wondering if there was a way to add padding between the child view controllers so that way they're not right next to one another.

Something that would look more like this:

enter image description here


Solution

  • check UIPageViewController init method

    - (id)initWithTransitionStyle:(UIPageViewControllerTransitionStyle)style navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation options:(NSDictionary *)opt

    you can pass your inter page space value to opt in UIPageViewControllerOptionInterPageSpacingKey