2016-11-28 187 views
0

我做了以下操作使導航欄變成白色。透明導航欄(swift 3)

UINavigationBar.appearance().shadowImage = UIImage() 
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default) 

因此,我將每個UIViewController設置爲「不在頂部/ bot欄」下。這看起來像我想要的。但是,當我做出UIImagePicker例如,它看起來是這樣的: navigation Bar

所以我試過如下:

let imagePicker = UIImagePicker() 
imagePicker.edgesForExtendedLayout = [] 

但它不工作。我如何做到這一點?

請注意!

回答

1

我不得不添加:

UINavigationBar.appearance().isTranslucent = false 

到我的AppDelegate。

謝謝Fonix和dfd

7

默認情況下導航欄不是白色嗎?像

UINavigationBar.appearance().shadowImage = UIImage() 
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default) 

將背景設置爲沒有數據的圖像,因此它將是透明的。如果您確實需要設置導航欄的顏色,請使用

UINavigationBar.appearance().barTintColor = UIColor.white 

而不是將背景設置爲圖像。您可能需要

self.navigationController!.navigationBar.isTranslucent = false 

裏面viewDidLoad中每個的viewController,但儘量不首先

1

試試這個在您的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假。