gpt4 book ai didi

ios - UIPageViewController 指示器不改变颜色

转载 作者:行者123 更新时间:2023-11-28 12:45:53 25 4
gpt4 key购买 nike

我在这里阅读了很多关于这个问题的帖子,看来现在最好的解决办法是按如下方式设置:

 let pageControl = UIPageControl.init(frame: CGRectMake(0, UIScreen.mainScreen().bounds.size.height*14/15, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
pageControl.backgroundColor = UIColor(red: 0, green: 147/255, blue: 229/255, alpha: 1)
pageControl.pageIndicatorTintColor = UIColor.lightGrayColor()
pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
view.addSubview(pageControl)

但出于某种原因,这对我不起作用。页面控件背景颜色改变,但指示器保持白色。

我的整个 viewDidLoad() 方法

override func viewDidLoad() {
super.viewDidLoad()
self.pageViewController = self.storyboard!.instantiateViewControllerWithIdentifier("OnboardingPageViewController") as! UIPageViewController

self.pageViewController.dataSource = self
let startingViewController:OnboardingPageContentViewController = self.viewControllerAtIndex(0)!

let viewControllers:Array<OnboardingPageContentViewController> = [startingViewController]

self.pageViewController.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)

let pageControl = UIPageControl.init(frame: CGRectMake(0, UIScreen.mainScreen().bounds.size.height*14/15, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
pageControl.backgroundColor = UIColor(red: 0, green: 147/255, blue: 229/255, alpha: 1)
pageControl.pageIndicatorTintColor = UIColor.lightGrayColor()
pageControl.currentPageIndicatorTintColor = UIColor.blackColor()
view.addSubview(pageControl)
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
self.addChildViewController(pageViewController)
self.view.addSubview(pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)

}

提前致谢

最佳答案

it appears that the best solution now is to set it as follows:

不,不是。您要添加一个 UIPageControl,但 UIPageViewController 已经有一个 UIPageControl。您想要的是设置那个 UIPageControl 的属性。

这样做的方法是使用appearance 代理。示例:

    let proxy = UIPageControl.appearance()
proxy.pageIndicatorTintColor = UIColor.redColor().colorWithAlphaComponent(0.6)
proxy.currentPageIndicatorTintColor = UIColor.redColor()
proxy.backgroundColor = UIColor.yellowColor()

关于ios - UIPageViewController 指示器不改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38148311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com