jbehrens94
jbehrens94

Reputation: 2396

iOS UIPageViewController with background

I have a container UIViewController (IntroViewController), in which I load a UIPageViewController (PageViewController). In the UIPageViewController, I have IntroPageContentViewControllers and a LastIntroPageContentViewController.

My storyboard setup

I want to have a background image in the UIPageViewController. If I put it in IntroViewController, it isn't viewable. I can't put it in the UIPageViewController, and when I put it in one of the ContentViewControllers it scrolls in and out with each page. I want it to be in one place and only scroll the content.

Where do I put the UIImageView and where should I bringSubviewToFront or something alike?

Upvotes: 0

Views: 858

Answers (3)

bevoy
bevoy

Reputation: 751

Simply put the UIImageView into container UIViewController and set view.backgroundColor property to [UIColor clearColor] for both content view controllers.

Here you have an example how it works: https://github.com/Wojdan/stackAnswers/tree/master/33912671

Upvotes: 2

Tekido
Tekido

Reputation: 19

Ideally, You should be adding UIPageViewControlleras child of it parentViewController. In your case IntroViewController is parent and PageViewController will become child of it.

Now, you set IntroViewController background colour from image like below :

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];

And then, you can clear background colours for content view controllers which are you planning to add into UIPageViewController.

However, you may have to comment below delegate to remove page control from bottom of `UIPageViewController'

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
}

Hope this helps.

Upvotes: 0

user5598510
user5598510

Reputation: 31

UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_backgroung"]];
imageView1.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[view addSubview:imageView1];

// Create page view controller
self.pageViewController = [self.storyboard 
instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.view.backgroundColor = [UIColor clearColor];                  
[self.pageViewController.view insertSubview:view atIndex:0];



UIPageControl *pageControl = [UIPageControl appearance];
 pageControl.pageIndicatorTintColor = [UIColor whisperWhite];
 pageControl.currentPageIndicatorTintColor = [UIColor whisperDarkGray];
 pageControl.backgroundColor = [UIColor clearColor];

Upvotes: 1

Related Questions