UIPageViewController和UIPageControl透明背景色 - iOS

hyd*_*d00 9 objective-c uipagecontrol ios uipageviewcontroller uibackgroundcolor

当应用程序第一次启动并使用时,我正在制作教程UIPageViewController.一切都很好,但背景颜色UIPageViewController不透明.它总是黑色的,如下所示:

在此输入图像描述 在此输入图像描述

这是我添加的方式UIPageViewController(在tabbar控制器中)

.h文件:

@interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource>

@property (strong, nonatomic) UIPageViewController *pageViewController;
@end
Run Code Online (Sandbox Code Playgroud)

.m文件(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];
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate.m中,我还设置了UIPageControl背景颜色以清除:

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
[pageControl setOpaque:NO];
self.window.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

我知道问题在于UIPageViewController背景颜色.是否无法将Controller的背景设置为透明?

请帮忙!

谢谢.

hyd*_*d00 4

好吧,我已经找到了解决方案:

  1. 在 上设置背景图像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];
Run Code Online (Sandbox Code Playgroud)
  1. 对于您的 PageViewController viewControllers,选择带有图形或任何您想要的 PNG 图像,但确保背景是透明的。
  2. 将您的UIPageControl背景设置为透明appDelegate.m

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

现在运行,您的UIPageViewController外观将如下所示(请注意,当我们从右向左滑动时,背景是静态的,只有文本在移动): 在此输入图像描述