问题描述
我偶然发现了很多次,从未找到解决方案.UINavigationController 的 navigationBar 可以设置为黑色半透明,例如:
I stumbled upon this many times, never found a solution.A UINavigationController's navigationBar can be set to black translucent like:
self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent;
此外,UINavigationBar 中有一个 translucent 属性,文档说:
Also, there is a translucent property in UINavigationBar, the docs say:
当为 YES 时,导航栏绘制为部分不透明,无论的酒吧风格.不透明度的数量是固定的,不能改变了.允许在以下情况下设置此属性的值导航栏由导航控制器对象管理.
我试过了
self.navigationcontroller.navigationBar.tintColor=[UIColor blueColor];
self.navigationcontroller.navigationBar.translucent=YES;
和一千种变化:首先设置 translucent 属性,在 AppDelegate 和 ViewController 中设置它,首先设置 barstyle.结果总是一样的:没有透明度.因此我的问题是:
and a thousand variations: Setting the translucent property first, setting it in the AppDelegate and in the ViewController, setting the barstyle first.The result is always the same: No transparency. Hence my question:
是否真的可以将半透明 UINavigationBar 的颜色更改为不同于黑色的颜色(最好在 UINavigationController 中)?
Is it really possible to change the color of a translucent UINavigationBar to something different than black (preferably within a UINavigationController)?.
我希望有一个审查安全的解决方案.
I hope there is a review-safe solution.
谢谢你
推荐答案
一旦你知道,它就相当简单:
Once you know it, it's fairly simple:
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.alpha = 0.7f;
self.navigationController.navigationBar.translucent = YES;
translucent
属性似乎只是确定主视图是否应该在导航栏下可见,并适当调整视图大小.
The translucent
property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.
这篇关于更改半透明黑色 UINavigationBar 的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!