ios - 如何使 UIPageViewController 背景半透明?

标签 ios uipageviewcontroller

我在网络上搜索并找到类似这样的答案(How do I make the bottom bar with dots of a UIPageViewController translucent?),但它并没有解决我的问题。

这是我的代码

    // PageControl Layout
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
//    pageControl.frame = CGRectMake(5,5,305,400);
pageControl = [UIPageControl appearanceWhenContainedIn:[self class], nil];

indexCurrentPage = 0;
pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
[pageController.view setFrame:[[UIScreen mainScreen] bounds]];
NSLog(@"page controller.fram  is %@", [NSValue valueWithCGRect:[[pageController view] frame]]);
pageController.dataSource = self;

GuidedTourPage *initialViewController = [self viewControllerAtIndex:0];
[[self.pageController view] setFrame:[[initialViewController view] bounds]];
NSLog(@"bound is %@", [NSValue valueWithCGRect:[[initialViewController view] bounds]]);
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[self.view addSubview:[pageController view]];
[pageController didMoveToParentViewController:self];

滚动功能和其他一切正常。除了缺少图像的一部分。 我在我的“AppDelegate.m”中做了 self.window.backgroundColor = [UIColor whiteColor]; 所以可以理解 pageControl.backgroundColor = [UIColor clearColor]; 将使背景为白色。

但我想要这样的东西 ( http://www.appcoda.com/wp-content/uploads/2013/06/UIPageViewController-Tutorial-Screen.jpg ),其中 pageControl 具有透明背景。

我知道问题出在图层上。但我不知道如何解决它。 有没有办法 NSLog 图层层次结构来检查它?或者有什么测试软件可以帮我测试图层问题。 我不认为这将是一个非常困难的问题,只要我能找到一种方法来调试图层,就像 Firefox 中的 3D-Inspect 元素功能一样。

提前致谢

最佳答案

试试这个:

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.backgroundColor = [UIColor clearColor];

你也可以玩 Alpha:

[[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.7];

因此,语句将变为:

pageControl.backgroundColor = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.7];

关于ios - 如何使 UIPageViewController 背景半透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22651309/

相关文章:

ios - 收到推送通知时使用协议(protocol)更新 UIViewController?

ios - UINavigationbar 项目位置不正确

swift - 无法连接页面 View Controller 上的按钮并使用按钮滑动到下一个屏幕

ios - UIPageViewController 在移动到第三个 View Controller 后取消分配第一个 View Controller ?

ios - 点击扫描平面时如何将 3D 对象添加到引用图像?

ios - 停止对SKSpriteKit的冲动

ios - 将字符串显示为带两位小数的数字

iphone - 使 UIView 全屏显示的问题

ios - 将 UIPageViewController 添加到 subview , subview 仅显示 pageContentview 的边缘

ios 页面 View Controller ,单面,中央书脊