透明导航栏(swift 3)
问题描述:
我做了以下操作使导航栏变成白色。透明导航栏(swift 3)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
因此,我将每个UIViewController设置为“不在顶部/ bot栏”下。这看起来像我想要的。但是,当我做出UIImagePicker例如,它看起来是这样的:
所以我试过如下:
let imagePicker = UIImagePicker()
imagePicker.edgesForExtendedLayout = []
但它不工作。我如何做到这一点?
请注意!
答
我不得不添加:
UINavigationBar.appearance().isTranslucent = false
到我的AppDelegate。
谢谢Fonix和dfd
答
默认情况下导航栏不是白色吗?像
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
将背景设置为没有数据的图像,因此它将是透明的。如果您确实需要设置导航栏的颜色,请使用
UINavigationBar.appearance().barTintColor = UIColor.white
而不是将背景设置为图像。您可能需要
self.navigationController!.navigationBar.isTranslucent = false
里面viewDidLoad中每个的viewController,但尽量不首先
答
试试这个在您的AppDelegate didFinishLaunchingWithOptions:
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = false
// these next lines aren't needed if you like the default
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.black] // shouldn't be needed, but if you want something
UINavigationBar.appearance().tintColor = UIColor.blue
我敢肯定,你需要设置isTranslucent假。