更改半透明黑色 UINavigationBar 的颜色 [英] Change color of translucent black UINavigationBar

查看:40
本文介绍了更改半透明黑色 UINavigationBar 的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了很多次,从未找到解决方案.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 时,导航栏绘制为部分不透明,无论的酒吧风格.不透明度的数量是固定的,不能改变了.允许在以下情况下设置此属性的值导航栏由导航控制器对象管理.

When YES, the navigation bar is drawn with partial opacity, regardless of the bar style. The amount of opacity is fixed and cannot be changed. It is permissible to set the value of this property when the navigation bar is being managed by a navigation controller object.

我试过了

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 的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆