iOS不同页面上的导航栏颜色不同 [英] iOS Different navigation bar color on different pages

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

问题描述

如何根据用户所在的页面来更改导航颜色 ?

How would I change the navigation bar color based on what page the user is on?

我想做的事情类似于Vine应用程序在用户点击某个类别时会在浏览类别中使用的功能,并且它会变成褪色格式的按钮颜色.有关如何执行此操作的任何想法?

I would like to do something similar to what the Vine app uses in the explore category when the user taps a certain category and it turns into the color of the button in a fading format. Any thoughts on how to do this?

推荐答案

您可以尝试像这样在prepareForSegue:方法(在您的控制器中用四个按钮)中设置导航栏的颜色

You can try to set the navigation bar tint color in the prepareForSegue: method (in your controller whit the four buttons) like this

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:"segueIdentifier here"]) { [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; } }

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:"segueIdentifier here"]) { [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; } }

当您回来时,请不要忘记重置导航栏的颜色(在viewWillAppear中执行此操作)

Don't forget to reset the navigation bar tint color when you came back (do this in the viewWillAppear)

或者您可以尝试在viewWillAppear方法的所有控制器中执行此操作:

Or you can try to do this in all your controllers in the method viewWillAppear: like this

- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; }

- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; }

这篇关于iOS不同页面上的导航栏颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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