UIPageViewController and UIPageControl transparent background color - iOS

后端 未结 2 1082
逝去的感伤
逝去的感伤 2021-01-04 21:48

I\'m making a tutorial when app launches for the first time and using UIPageViewController for that. Everything is working fine but the background color of

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 22:04

    Okay I've found the solution:

    1. Set a background image on 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 , choose a PNG Image with graphics or whatever you want, but make sure the background is transparent.
    2. Set your UIPageControl's 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, (notice the background static and only the text is moving, as we swipe from right to left):

提交回复
热议问题