Make navigation bar transparent regarding below image in iOS 8.1

主宰稳场 提交于 2019-12-18 03:38:24

问题


I try to set my navigation bar transparent regarding a image below this, something like the following image :

I tried the solution in transparent navigation bar ios but I don't get the above result, I get only the icon on the left but without any color in the navigation bar, completely transparent. But if I set a background color the transparency disappears at all.

There is any way to set a color in the navigation bar and make it transparent??

Thanks in advance.


回答1:


just checked on the 8.1 simulator and got very similar result to your picture

    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)

main point here is background color with alpha.

Check attached image, maybe I missed something?




回答2:


To set this style globally, use the UIAppearance APIs. In AppDelegate's application:didFinishLaunchingWithOptions: add the following code:

// 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



回答3:


Have you tried setting the navigationBar's alpha property? In your root view controller to the navigation controller...

[self.navigationController.navigationBar setBackgroundColor:[UIColor greenColor]];
[self.navigationController.navigationBar setAlpha:0.3f];



回答4:


self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.isTranslucent = true

If the above code is not working then set edgesForExtendedLayout to all.

self.edgesForExtendedLayout = .all


来源:https://stackoverflow.com/questions/27708943/make-navigation-bar-transparent-regarding-below-image-in-ios-8-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!