UIPageViewController和UIPageControl透明背景色-iOS
当应用程序第一次启动时,我正在制作一个教程,并使用UIPageViewController和UIPageControl透明背景色-iOS,ios,objective-c,uipageviewcontroller,uipagecontrol,uibackgroundcolor,Ios,Objective C,Uipageviewcontroller,Uipagecontrol,Uibackgroundcolor,当应用程序第一次启动时,我正在制作一个教程,并使用UIPageViewController。一切正常,但UIPageViewController的背景色不透明。始终为黑色,如下所示: 下面是我如何添加UIPageViewController(在选项卡栏控制器中) .h文件: @interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource> @property (str
UIPageViewController
。一切正常,但UIPageViewController
的背景色不透明。始终为黑色,如下所示:
下面是我如何添加UIPageViewController
(在选项卡栏控制器中)
.h文件:
@interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageViewController;
@end
在我的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];
我知道问题出在UIPageViewController
的背景色上。无法将控制器的背景设置为透明吗
请帮忙
谢谢。好的,我找到了解决方案:
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:[UIImageName:@“登录背景”];
imageView1.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
[视图添加子视图:图像视图1]代码>
// 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];
对于您的PageViewControllerViewController
,请选择带有图形或任何所需内容的PNG图像,但请确保背景是透明的
在appDelegate.m
UIPageControl*pageControl=[UIPageControl外观];
pageControl.pageIndicatorTintColor=[UIColor White];
pageControl.currentPageIndicatorTintColor=[UIColor];
pageControl.backgroundColor=[UIColor clearColor]代码>
现在运行,您的UIPageViewController
将如下所示(注意背景静态,只有文本在移动,我们从右向左滑动):
在显示页面视图控制器之前,将其设置为页面视图控制器
pageViewController.providesPresentationContextTransitionStyle = YES;
pageViewController.definesPresentationContext = YES;
[pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
这修复了我没有背景图像的问题,我希望页面控制器后面的内容能够通过。
pageViewController.providesPresentationContextTransitionStyle = YES;
pageViewController.definesPresentationContext = YES;
[pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];