ios - 如何在 UIPageViewController 中从一页动画到另一页时设置 View 的背景颜色

标签 ios swift

在我的UIPageViewController中,我想在从一个页面拖动到另一页面时设置不同的背景颜色。所以我的默认颜色将在那里,但会在不同的索引过渡上显示不同的颜色。目前,在我的 UIPageViewControllerDelegate 下,我正在获取当前页面的索引号:

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {

        if let firstViewController = viewControllers?.first,
            let index = orderedViewControllers.index(of: firstViewController) {
            viewControllerDelegate?.pageViewController(pageViewController: self, didUpdatePageIndex: index)

            if index == 0 {

                (parent as? MainViewController)?.container.backgroundColor = UIColor.red
            }
            else if index == 1 {

                (parent as? MainViewController)?.container.backgroundColor = UIColor.black
            }

        }


    }

但是我如何设置它们之间的颜色。

最佳答案

将其添加到didFinishLaunchingWithOptions

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor blueColor];
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
pageControl.backgroundColor = [UIColor blackColor];

如果您想设置外观,请添加以下行:

UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[MyViewController class], nil];

关于ios - 如何在 UIPageViewController 中从一页动画到另一页时设置 View 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42083209/

相关文章:

ios - FSCalendar 跳转至 1970 年

ios - 何时使用 dequeueReusableCellWithIdentifier 与 dequeueReusableCellWithIdentifier : forIndexPath

ios - 在哪里可以找到 iPhone 设备的 UDID?如果 iTunes 预计会在 macOS 10.15 之前退役,预计会在 wwdc19 中公布

ios - 我怎样才能普遍禁用横向?

swift - Typhoon Swift Framework - 如何在初始化器中注入(inject)参数

php - HTTPS 问题 iOS9

ios - 由于未捕获的异常 'NSRangeException' 终止应用程序,原因 : -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' - 2

ios - swift 4 : How to create a face map with ios11 vision framework from face landmark points

ios - Swift 3.0 AVAudioPlayer 通过音乐播放音频

ios - 在attributeText中添加链接修饰符后,范围内的文本变得不可见