UINavigationBar外观刷新吗? [英] UINavigationBar appearance refresh?

查看:117
本文介绍了UINavigationBar外观刷新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPad应用程序中,我有一个应用程序设置视图。选项之一使用户可以切换界面颜色方案。设置视图通过segue加载到我的主应用程序窗口之外的单独的视图控制器中。

In my iPad app I have an application settings view. One of the options lets the user switch interface color scheme. The settings view is loaded by segue to a separate view controller than my "main" app's window.

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

When they pick a new color I switch the colorSchemeColor variable and do this:

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

但是,在我退出设置视图之前,所有条形都不会改变颜色! (当设置窗口消失时,主应用程序的颜色将正确更改!)

However, none of the bars change color until I exit my settings view! (When the settings window disappears, the colors for the "main" app change correctly!)

因此,我尝试在刷新设置视图后立即放置此代码:

So then I tried to put this code right after to refresh the settings view:

[self.view setNeedsDisplay];
[self.view setNeedsLayout];

这没有帮助。所以我也添加了它:

which didn't help. So I added this as well:

[self.navigationController.view setNeedsDisplay];
[self.navigationController.view setNeedsLayout];

这也不起作用。

选择新颜色后如何使设置视图重绘自身,使更改立即显而易见?

How can I get my settings view to "redraw" itself when the new color is picked so the change is instantly obvious?

非常感谢!

推荐答案

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

The appearance proxy only affects the look of newly initialized views. Setting colors on the appearance proxy will have no effect on navigation bars that are already visible.

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

You'll need to manually update your current view; for example:

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

这篇关于UINavigationBar外观刷新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆