2017-08-29 57 views
1

我的导航栏是透明的,只有我的应用中显示的栏按钮处于透明状态。在我的故事板中,我没有标题,因此导航栏看起来没有任何内容,但是当我运行模拟器时,我删除的文本位于导航栏中。导航栏在模拟器中显示文本,但不显示故事板

这是我找到了解决问题:

导航栏应该是什么样子不透明度

What the nav bar should look like without the transparency (in Storyboard)

导航栏的样子在模拟器

What the nav bar looks like in the simulator

我制作的酒吧透明代码:

//Makes navigation bar translucent   
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default) 
self.navigationController?.navigationBar.shadowImage = UIImage() 
self.navigationController?.navigationBar.isTranslucent = true 
+0

请检查我的答案 – cole

回答

0

在你的代码,内部视图将出现方法 使用此代码

self.title = "" // or whatever text you have 

在您的应用程序委托,去把与选择的方法启动:

UINavigationBar.appearance().barTintColor = .white 
    UINavigationBar.appearance().isTranslucent = false 

    UINavigationBar.appearance().titleTextAttributes = 
    [NSForegroundColorAttributeName: UIColor.black] // shouldn't be needed, but if you want something 
    UINavigationBar.appearance().tintColor = .blue 

从您的故事中删除您所做的任何更改。它可以从代码完成,也因为它需要在应用程序中保持一致。尝试从代码本身处理状态栏和导航栏。

+0

我编辑它以清除并评论我的代码。它不会让导航栏像我想要的那样透明。 –

+0

@ M.Bi请检查我的更新答案 – cole