使iOS 8.1中的下方图像的导航栏透明

Vic*_*ler 7 ipad swift ios8.1

我尝试将导航栏设置为透明,对于下面的图像,如下图所示:

在此输入图像描述

我在透明导航栏ios中尝试了解决方案,但是我没有得到上面的结果,我只得到左侧的图标,但导航栏中没有任何颜色,完全透明.但如果我设置背景颜色,透明度就会消失.

有没有办法在导航栏中设置颜色并使其透明?

提前致谢.

sag*_*444 30

只需在8.1模拟器上查看并获得与您的图片非常相似的结果

    let bar:UINavigationBar! =  self.navigationController?.navigationBar

    bar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    bar.shadowImage = UIImage()
    bar.backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
Run Code Online (Sandbox Code Playgroud)

这里的主要观点是带有alpha的背景颜色.

检查附图,也许我错过了什么?

在此输入图像描述


nic*_*aef 13

要全局设置此样式,请使用UIAppearance API.在AppDelegate中application:didFinishLaunchingWithOptions:添加以下代码:

// Sets background to a blank/empty image
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
// Sets shadow (line below the bar) to a blank image
UINavigationBar.appearance().shadowImage = UIImage()
// Sets the translucent background color
UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
// Set translucent. (Default value is already true, so this can be removed if desired.)
UINavigationBar.appearance().translucent = true
Run Code Online (Sandbox Code Playgroud)