简体   繁体   English

尝试更改导航栏背景颜色,但失败

[英]try to change navigationbar background color but failed

I used the code below to change the background color of navigationbar 我使用下面的代码更改了导航栏的背景颜色

- (void)viewDidLoad
{

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithHexString:@"6cd3c5"]];

    [super viewDidLoad];

}

the bar background color does not change immediately, I have to pushViewController:someViewController 酒吧背景颜色不会立即改变,我必须pushViewController:someViewController

and go back, the color can change. 然后返回,颜色可能会改变。

Your comment welcome 欢迎您发表评论

Try this: 尝试这个:

[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithHexString:@"6cd3c5"]];
[self.navigationController.navigationBar setTranslucent:NO];

Read this for more clarification. 阅读此内容以获得更多说明。

appearance is used for the future appearance. appearance用于将来的外观。 if you want to appearance then use before the view load. 如果要显示外观,请在加载视图之前使用。

else use 否则使用

    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithHexString:@"6cd3c5"]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM