如何在iOS 7中使导航栏透明? [英] How to make navigation bar transparent in iOS 7?

查看:128
本文介绍了如何在iOS 7中使导航栏透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让导航控制器的栏完全透明?

Is there a way to make the bar of a navigation controller totally transparent?

我尝试了什么:

[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];
[self.navigationController.navigationBar setAlpha:0.0];

但是酒吧的外观不会改变,并保持白色半透明。
我试图看到酒吧项目,但不是酒吧本身。有人能指出我正确的方向吗?谢谢

but the bar's appearance does not change, and stays white translucent. I'm trying to get visible the bar items, but not the bar itself. Can someone point me in the right direction? Thanks

推荐答案

如果有人想知道如何在iOS 7中实现这一点,这里有一个解决方案(iOS 6兼容)

If anybody is wondering how to achieve this in iOS 7, here's a solution (iOS 6 compatible too)

[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;

由于UINavigationBar文档中讨论的行为,导航栏上的半透明设置为YES可以解决问题。我将在此处报告相关片段:

Setting translucent to YES on the navigation bar does the trick, due to a behaviour discussed in the UINavigationBar documentation. I'll report here the relevant fragment:

如果在具有不透明自定义背景图像的导航栏上将此属性设置为YES,则导航栏将应用系统不透明度小于1.0的图像。

If you set this property to YES on a navigation bar with an opaque custom background image, the navigation bar will apply a system opacity less than 1.0 to the image.

参考来自:制作UINavigationBar透明

这篇关于如何在iOS 7中使导航栏透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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