我已将 UIPageViewController 嵌入到 Root View Controller 中。
如下图所示。
但是我想将第一个、第二个 View Controller 背景设置为透明,并且它仍然可以显示 View Controller 文本1和2。
因此它将显示根背景颜色(黑色),并且 Root View Controller 可以在 uipageviewcontroller 中滑动。
我的pageviewcontroller部分代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:@"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:@"Intro2ID"];
myViewControllers = @[p1,p2];
[self setViewControllers:@[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
有谁可以教我如何将containerview背景颜色设置为透明并可以显示1、2个文本吗? (这是示例代码,因此只有 1、2 个文本)
非常感谢。
最佳答案
这应该可以解决问题:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
问题是 UIViewController
的背景 View 不透明。
关于iOS 如何在容器 View Controller 中设置透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28233139/