使用UIAppearance更改后更新导航栏 [英] Updating navigation bar after a change using UIAppearance

查看:296
本文介绍了使用UIAppearance更改后更新导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前定制使用UIAppearance代理我的iOS应用程序的导航栏的背景图片。存在用于触发通知两种不同模式之间进行切换的按钮。此通知将再次改变使用代理后台不同的图像。我的问题是,只有当我去到不同的控制器和我回来给它这种变化变得可见。我不能够迫使控制器内导航栏的更新。

I'm currently customising the navigation bar background image of my iOS app using the UIAppearance proxy. There is a button for switching between two different modes which triggers a notification. This notification will change the background to a different image using again the proxy. My problem is that this change becomes visible only when I go to a different controller and I come back to it. I'm not able to force the update of the navigation bar within the controller.

我在我的MainTabBarController尝试这样:

I've tried this in my MainTabBarController:

- (void) onAppChangedMode: (NSNotification*)notif {

APP_MODE mode = (APP_MODE) [[notif object] integerValue];

// change navigation bar appearance
[[UILabel appearance] setHighlightedTextColor:[UIColor redColor]];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:(mode == 0 ? @"navbar.png" : @"navbar2.png")] forBarMetrics:UIBarMetricsDefault];
// trying to update
for (UIViewController* vc in self.viewControllers) {
     [vc.navigationController.navigationBar setNeedsDisplay];
}

}

但没有什么...它不工作。任何想法如何实现呢?

but nothing...it's not working. Any idea how to achieve it?

谢谢!

推荐答案

试试这个code键更改背景图像的目前的导航栏只有

Try this code to change the background image for the current nav bar only:

[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

使用上述code更改UIAppearance后。这将迫使电流控制器的导航栏的变化。对于其他控制器的导航栏将在UIAppearance变化进行处理。

Use the above code after changing the UIAppearance. This will force a change in the nav bar of the current controller. The nav bars for the other controllers will be handled by the change in UIAppearance.

这篇关于使用UIAppearance更改后更新导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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