ios - 透明的 iOS 导航栏

标签 ios iphone swift uinavigationbar

我正在创建一个应用程序,我在互联网上浏览过,我想知道他们是如何制作这个透明的 UINavigationBar 的:

enter image description here

我在我的 appdelegate 中添加了以下内容:

UINavigationBar.appearance().translucent = true

但这只是让它看起来像下面这样:

enter image description here

如何使导航栏像第一张图片一样透明?

最佳答案

您可以像下面那样为半透明应用导航栏图像。

objective-C :

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault]; //UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.shadowImage = [UIImage new];////UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

swift 3:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) //UIImage.init(named: "transparent.png")
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
    

关于ios - 透明的 iOS 导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25845855/

相关文章:

ios - UIImagePickerController - 集合在枚举时发生变异

ios - 如何使 View Controller 从左侧显示并且不填充整个 View ?

ios - 6.0.1 和表更改 "UILabel? does not have a member named ' 文本”

iphone - 如何在应用程序 iphone 中添加 .vcf 文件作为附件

javascript - 当我尝试接收用户电子邮件的数据时,为什么我的 Firebase 云函数代码会抛出错误

ios - 在 XCode 4 中创建两个目标

iphone - 如何在 Objective-C 中解析文本文件?

iphone - 防止ios模拟器询问 "x Would like to use your current location"

ios - Swift - 子类 UICollectionViewCell 不加载 IBOutlet 属性

swift - 由于两个存储的属性在 Swift 中不以任何方式交互,因此如何保持内存安全?