如何使UINavigationBar背景透明? [英] How to make UINavigationBar background transparent?

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

问题描述

首先,
我已经看到



我正在使用(在 viewDidLoad viewWillAppear:):

  [self.navigationController.navigationBar了setBackgroundImage: UIImage new] 
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

我收到了这个:





灰色状态栏背景,完全白色导航栏,不与状态栏混合,然后视图开始。其他问题答案中的所有解决方案对我产生相同的结果。



我也尝试过设置 self.edgesForExtendedLayout = UIRectEdgeNone; self.edgesForExtendedLayout = UIRectEdgeAll; 但这也没有任何影响。



如何在不弄乱所有内容的情况下使导航栏变得透明?



更新:在Warif Akhand Rishi的回答之后,我已经更改 self.navigationController.view.backgroundColor = [UIColor clearColor]; 改为 self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; ,现在我得到一个灰色的统一状态/导航栏,但仍然不透明:





更新2:我已经连接了视图调试器,并且在灰色背景似乎来自视图层次结构的根本深处,我的视图内容没有扩展。我已尝试 self.edgesForExtendedLayout = UIRectEdgeAll; 再次使用最新代码但仍然无效:



解决方案

好吧,经过努力,我已经解决了这个问题。有不止一个问题。这不是关于扩展的边缘,它是关于自我行.navigationController.view.backgroundColor = [UIColor clearColor]; (必须是 self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; 正如Warif Akhand Rishi建议的那样)以及我的表格视图的剪辑子视图属性。我已经更改了那一行并且还关闭了我的表视图的剪辑,现在它按预期工作。


First of all, I've seen all the answers at How to make UINavigationBar Transparent in IOS 8? Transparent UINavigationBar and Make UINavigationBar transparent.

They just don't seem to work for me.

My regular view controller (before trying to make the navigation bar transparent) doesn't have any issues:

I'm using (tried both in viewDidLoad and viewWillAppear:):

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                              forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

I'm getting this:

Gray status bar background, completely white navigation bar which doesn't blend with the status bar, and then the view starts. All the 'solutions' at the other questions' answers' yield the same result for me.

I've also tried setting self.edgesForExtendedLayout = UIRectEdgeNone; or self.edgesForExtendedLayout = UIRectEdgeAll; but that also didn't have any impact.

How can I make my navigation bar transparent without messing up everything?

UPDATE: Following Warif Akhand Rishi's answer, I've changed self.navigationController.view.backgroundColor = [UIColor clearColor]; to self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];, now I'm getting a gray, unified status/navbar, but still not transparent:

UPDATE 2: I've hooked up the view debugger, and that gray background seems to come from deep down from the roots of view hierarchy, and my view's content is not extending up. I've tried self.edgesForExtendedLayout = UIRectEdgeAll; again with the latest code but still no avail:

解决方案

Okay, after struggling, I've solved the problem on my own. There was more than one problem. It wasn't about the extended edges, it was about the line self.navigationController.view.backgroundColor = [UIColor clearColor]; (which had to be self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; as Warif Akhand Rishi suggested) and also my table view's clip subviews property. I've changed that line and also turned off clipping of my table view and now it works as expected.

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

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