ios - 导航栏背景色-半透明为无

标签 ios objective-c uinavigationcontroller uinavigationbar

我想将导航栏的背景颜色更改为纯绿色。

规则:我不能乱用 AppDelegate :)

我试过:

//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]];

有什么想法吗?

谢谢,没看到还有 barTintColor 和 TintColor。接受最早的答案。

最佳答案

在您的 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] 

关于ios - 导航栏背景色-半透明为无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19094710/

相关文章:

ios - 构建ios应用,以便iPad使用iPhone屏幕尺寸

objective-c - 在 Objective-C 中实现协议(protocol)特定方法

ios - 让 UIView 响应快速、快速的单击的最佳方法是什么?

ios - 导航标题颜色变化问题

ios - 状态栏下的 Swift 导航栏

ios - 如何在容器 View 中显示 WKWebView 内容

ios - 在 Swift 中,我如何将永久变量从主 iOS 应用程序传递到扩展程序(例如今天的扩展程序、自定义键盘)

ios - 用 UIGraphicsImageRenderer 的 jpegData 替换 UIImageJPEGRepresentation

ios - 如何将乘数应用于在 nib 文件上创建的所有约束?

objective-c - 执行获取请求 :error: freezes app