本文介绍了使UINavigationBar透明化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使 UINavigationBar透明?虽然我希望它的条形项目保持可见。
How do you make a UINavigationBar transparent? Though I want its bar items to remain visible.
推荐答案
如果有人想知道如何在iOS 7+中实现这一点,这里有一个解决方案(iOS 6兼容)
If anybody is wondering how to achieve this in iOS 7+, here's a solution (iOS 6 compatible too)
在Objective-C中
In Objective-C
[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
在swift 3(iOS 10)中
In swift 3 (iOS 10)
self.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true
在swift 2中
self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true
讨论
由于文档。我将在此处报告相关片段:
Discussion
Setting translucent
to YES
on the navigation bar does the trick, due to a behavior discussed in the UINavigationBar
documentation. I'll report here the relevant fragment:
这篇关于使UINavigationBar透明化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!