Ios 如何在UIPageViewController中设置从一页到另一页的动画时设置视图的背景色
在myIos 如何在UIPageViewController中设置从一页到另一页的动画时设置视图的背景色,ios,swift,Ios,Swift,在myUIPageViewController中,我想在从一页拖动到另一页时设置不同的背景色。因此,我的默认颜色将在那里,但会显示不同的索引转换不同的颜色。目前,在myUIPageViewControllerDelegate下,我正在获取当前页面的索引号: func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewContro
UIPageViewController
中,我想在从一页拖动到另一页时设置不同的背景色。因此,我的默认颜色将在那里,但会显示不同的索引转换不同的颜色。目前,在myUIPageViewControllerDelegate
下,我正在获取当前页面的索引号:
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中
如果要设置外观,请添加以下行:
您在数组中的颜色如下所示
let Array: [(name: String, color: UIColor)] = [("Red", UIColor.red), ("Blue", UIColor.blue),("Green", UIColor.green)]
print( Array[index]) // index is Your array indexNumber.
并以背景色传递此数组值
(parent as? MainViewController)?.container.backgroundColor = [Pass this array index color]
只需将窗口背景色设置为您所需的颜色。这是什么意思?
ui窗口
background color。什么外观?它就像颜色一样。
let Array: [(name: String, color: UIColor)] = [("Red", UIColor.red), ("Blue", UIColor.blue),("Green", UIColor.green)]
print( Array[index]) // index is Your array indexNumber.
(parent as? MainViewController)?.container.backgroundColor = [Pass this array index color]