UIPageViewController和UIPageControl透明背景颜色
我在第一次启动应用程序时使用UIPageViewController
进行教程。 一切工作正常,但UIPageViewController
的背景颜色不透明。 它总是黑色的,如下所示:
以下是我如何添加UIPageViewController
(在UIPageViewController
控制器中)
.h文件:
@interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageViewController;
@end
.m文件(在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];
在我的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:[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];
viewControllers
,选择一个PNG图像与图形或任何你想要的,但确保背景是透明的。 设置你的UIPageControl
的背景为透明appDelegate.m
UIPageControl *pageControl = [UIPageControl appearance]; pageControl.pageIndicatorTintColor = [UIColor whisperWhite]; pageControl.currentPageIndicatorTintColor = [UIColor whisperDarkGray]; pageControl.backgroundColor = [UIColor clearColor];
现在运行,你的UIPageViewController
看起来就像这样(注意背景是静态的,只有文本正在移动,因为我们从右向左滑动):
在呈现之前将它们设置为页面视图控制器
pageViewController.providesPresentationContextTransitionStyle = YES;
pageViewController.definesPresentationContext = YES;
[pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
链接地址: http://www.djcxy.com/p/88801.html
上一篇: UIPageViewController and UIPageControl transparent background color