[英]Navigation bar background color - translucency is no
I would like to change the background color of the navigation bar to a solid green. 我想将导航栏的背景颜色更改为纯绿色。
Rule: I can't mess with the AppDelegate :) 规则:我不能乱用AppDelegate :)
I've tried: 我试过了:
//It's green but it's translucent
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//It's white, first line has no effect
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
[self.navigationController.navigationBar setTranslucent:NO];
//Same result as case 1
[self.navigationController.navigationBar setAlpha:0.0f];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//Too dark
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//Only affects the back button's color:
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
So any ideas? 那么任何想法?
Thank you, didn't see there was barTintColor and TintColor as well. 谢谢,没看到有barTintColor和TintColor。 Accepting earliest answer.
接受最早的答案。
在viewController didLoad方法中使用以下代码行
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29.0f/255.0f green:149.0f/255.0f blue:174.0f/255.0f alpha:1.0f]
使用这一个,
self.navigationController.navigationBar.tintColor=[UIColor colorWithRed:19.0/255.0f green:52.0/255.0f blue:36.0/255.0f alpha:1];
请使用以下代码可能会对您有所帮助。
navController.navigationBar.barTintColor = [UIColor yourcolor];
使用navigationBar的barTintColor属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.