UIPageViewController and UIPageControl transparent background color - iOS

I run the tutorial when the application starts for the first time and using the UIPageViewController to do this. Everything works fine, but the background color of the UIPageViewController does not become transparent. It is always black, as shown below:

enter image description here enter image description here

This is how I add the UIPageViewController (in the panel controller)

.h file:

 @interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource> @property (strong, nonatomic) UIPageViewController *pageViewController; @end 

.m file (in viewDidLoad ):

 // Create page view controller self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"]; self.pageViewController.dataSource = self; self.pageViewController.view.backgroundColor = [UIColor clearColor]; TutorialViewController *startingViewController = [self viewControllerAtIndex:0]; NSArray *viewControllers = @[startingViewController]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; [self presentViewController:_pageViewController animated:YES completion:nil]; 

in my AppDelegate.m, I also set the background color of the UIPageControl to clear:

 UIPageControl *pageControl = [UIPageControl appearance]; pageControl.pageIndicatorTintColor = [UIColor lightGrayColor]; pageControl.currentPageIndicatorTintColor = [UIColor blackColor]; pageControl.backgroundColor = [UIColor clearColor]; [pageControl setOpaque:NO]; self.window.backgroundColor = [UIColor clearColor]; 

I know the problem is with the background color of the UIPageViewController . Is it impossible to set the background transparency of the controller?

Please, help!

Thanks.

+8
ios objective-c uipageviewcontroller uibackgroundcolor uipagecontrol
source share
2 answers

Ok, I found a solution:

  • Set the background image to the UIPageViewController .

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]; 
  1. For your PageViewController viewControllers select a PNG image with graphics or whatever you want, but make sure the background is transparent.
  2. Set the UIPageControl background as transparent in appDelegate.m

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

Now run, and your UIPageViewController will look like this: (pay attention to the static background and only the text moves, as we scroll from right to left): enter image description here

+3
source share

Install them on the pageview controller before submitting it

 pageViewController.providesPresentationContextTransitionStyle = YES; pageViewController.definesPresentationContext = YES; [pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext]; 
+1
source share

All Articles