在我的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
}
}
}
但是如何在它们之间设置颜色。
答案 0 :(得分:0)
在 didFinishLaunchingWithOptions
中添加此内容UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor blueColor];
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
pageControl.backgroundColor = [UIColor blackColor];
如果要设置外观,请添加以下行:
UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[MyViewController class], nil];
答案 1 :(得分:0)
您在阵列中的颜色
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]