问题描述
如何根据用户所在的页面来更改导航栏颜色 ?
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不同页面上的导航栏颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!