1 个导航控制器内有不同的导航栏色调?

发布于 2024-09-07 01:14:25 字数 445 浏览 0 评论 0原文

我的应用程序有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2024-09-14 01:14:30

原因是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

哥,最终变帅啦 2024-09-14 01:14:29

您应该能够在 viewWillAppearviewDidAppear 中执行 self.navigationController.navigationBar.tintColor = [UIColor blackColor];

You should be able to do the self.navigationController.navigationBar.tintColor = [UIColor blackColor]; in viewWillAppear or viewDidAppear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文