如何更改特定视图上导航栏的颜色 [英] How to change the color of navigation bar on a specific view

查看:16
本文介绍了如何更改特定视图上导航栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要在某些特定视图上更改导航栏的颜色.关于修改导航栏颜色的讨论很多,比如https://stackoverflow.com/a/18870519/938380,但它们都在同一导航层次结构下的每个视图上更改导航栏的颜色.

I need to change the color of my navigation bar on only some specific views. There are many discussions about modifying the color of navigation bar, like https://stackoverflow.com/a/18870519/938380, but they all change the color of navigation bar on every views under the same navigation hierarchy.

我想更改特定视图的颜色并使其他视图保持相同的颜色.我如何实现这一目标?

I want to change the color on specific views and keep other views the same color. How do I achieve this?

推荐答案

如果使用标准导航栏,则无法做到.但是您可以使用一些作弊方法;) 例如,您可以将此代码(或类似代码)添加到您的控制器中:

if you use standart navigation bar, you can't do it. But you can use some cheat ;) For example, you can add this code(or something like this) to your controller:

 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
     oldColor = self.navigationController.navigationBar.backgroundColor;//probably barTintColor instead of backgroundColor
     self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];
 }
 - (void)viewWillDisappear:(BOOL)animated {
     [super viewWillDisappear:animated];
     self.navigationController.navigationBar.backgroundColor = oldColor;
 }

这篇关于如何更改特定视图上导航栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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