我有透明导航栏,带有视图控制器的背景图像,但是当我向导航栏添加一个条形按钮项时,它就像在第二张图片中一样。我如何将条形按钮项目也完全透明导航栏。
我使用下面的代码使导航栏透明;
extension UINavigationController {
public func presentTransparentNavigationBar() {
navigationBar.setBackgroundImage(UIImage(), forBarMetrics:UIBarMetrics.Default)
navigationBar.translucent = true
navigationBar.shadowImage = UIImage()
setNavigationBarHidden(false, animated:true)
}
public func hideTransparentNavigationBar() {
setNavigationBarHidden(true, animated:false)
navigationBar.setBackgroundImage(UINavigationBar.appearance().backgroundImageForBarMetrics(UIBarMetrics.Default), forBarMetrics:UIBarMetrics.Default)
navigationBar.translucent = UINavigationBar.appearance().translucent
navigationBar.shadowImage = UINavigationBar.appearance().shadowImage
}
}
答案 0 :(得分:5)
这应该创建一个透明的UINavigationBar
,其中包含项目。它目前对我来说很好。
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = UIColor.whiteColor()
navigationBarAppearace.translucent = true
navigationBarAppearace.shadowImage = UIImage()
navigationBarAppearace.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
navigationBarAppearace.setBackgroundImage(UIImage(), forBarMetrics: .Default)
答案 1 :(得分:4)
尝试:
if let navBar = self.navigationController?.navigationBar {
extendedLayoutIncludesOpaqueBars = true
navigationBar.translucent = true
navigationBar.backgroundColor = UIColor.clearColor()
navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationBar.shadowImage = UIImage()
}