gpt4 book ai didi

uinavigationbar - UINavigationBar外观刷新吗?

转载 作者:行者123 更新时间:2023-12-03 11:45:15 29 4
gpt4 key购买 nike

在我的iPad应用程序中,我有一个应用程序设置 View 。选项之一允许用户切换界面颜色方案。通过segue将设置 View 加载到与“主”应用程序窗口不同的单独 View Controller 中。

当他们选择新颜色时,我切换了colorSchemeColor变量并执行以下操作:

// set the colors and refresh the view
[[UINavigationBar appearance] setBarTintColor:colorSchemeColor];
[[UIToolbar appearance] setBarTintColor:colorSchemeColor];
[[UITabBar appearance] setBarTintColor:colorSchemeColor];

但是,直到我退出设置 View ,所有条形都不会改变颜色! (当设置窗口消失时,“主”应用程序的颜色将正确更改!)

因此,我尝试在刷新设置 View 后立即放置此代码:
[self.view setNeedsDisplay];
[self.view setNeedsLayout];

这没有帮助。所以我也添加了这个:
[self.navigationController.view setNeedsDisplay];
[self.navigationController.view setNeedsLayout];

这也不起作用。

选择新颜色后,如何使设置 View 能够“重绘”自身,使更改立即显而易见?

非常感谢!

最佳答案

外观代理仅影响新初始化 View 的外观。在外观代理上设置颜色将不会影响已经可见的导航栏。

您需要手动更新当前 View ;例如:

self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor;

关于uinavigationbar - UINavigationBar外观刷新吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652957/

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