1 个导航控制器内有不同的导航栏色调?
我的应用程序有一个带有 2 个视图的导航视图控制器:
- 根视图:我希望其导航栏的色调为黑色
- 子视图:我希望其导航栏的色调颜色为蓝色
为此,我在每个视图控制器的 viewDidLoad 方法中设置导航栏的色调颜色: self.navigationController.navigationBar.tintColor = [UIColor blackColor];
我的问题是在测试过程中:
- 步骤 1 - 我访问根视图:导航栏是黑色的:好的
- 第 2 步 - 我推送子视图:导航栏是蓝色的:好的
- 步骤 3 - 我单击子视图的“后退”按钮:导航保持蓝色:KO
是否有任何我应该添加的添加代码以获得我想要的行为? (我尝试过一些肮脏的解决方法,例如在 viewWillAppear 中调用drawRect,但它不起作用)
感谢您的帮助!
My application has a navigation view controller with 2 views :
- a root view : i'd like the tint color for its navigation bar to be black
- a sub view : i'd like the tint color for its navigation bar to be blue
To achieve this, I set the tint color for the navigation bar in the viewDidLoad method of each view controller :self.navigationController.navigationBar.tintColor = [UIColor blackColor];
My problem is that during the tests :
- step 1 - i access the root view : the navigation bar is black : OK
- step 2 - i push the subview : the navigation bar is blue : OK
- step 3 - i click on the "back" button of the subview : the navigation remains blue : KO
Is there any add code I should add to obtain the behavior I want ?
(i've tried some dirty workarounds like calling drawRect in viewWillAppear but it does not work)
Thanks for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因是navigationController是共享的。因此,当您将其颜色更改为蓝色时,您必须将其更改回黑色。
最好的方法就像 Elfred 所说,你应该在 viewWillAppear 中执行它
The reason is that the navigationController is shared. So, when you change its color to Blue, you have to change it back to Black.
The best way is like Elfred said, you should do it in viewWillAppear
您应该能够在
viewWillAppear
或viewDidAppear
中执行self.navigationController.navigationBar.tintColor = [UIColor blackColor];
You should be able to do the
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
inviewWillAppear
orviewDidAppear