Search code examples
iosswiftuinavigationbar

Changing alpha value of navigationbar so underlying objects are visible


I want to implement a translucent NavigationBar so underlying objects are visible.

It should look like here:

enter image description here

This view is a custom view which uses alpha value to achieve the translucency behavior.

I tried this to implement my custom NavigationBar like this:

    UINavigationBar.appearance().barTintColor = .white
    UINavigationBar.appearance().tintColor = UIColor(netHex: CxtColor.black.rawValue)
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().isTranslucent = true
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    UINavigationBar.appearance().inputView?.alpha = 0.4
    UINavigationBar.appearance().alpha = 0.4

But its not translucent and also the changing of the alpha value has no really effect on the NavigationBar. Its just a white navigationbar.

I don't want to create a full transparent navigationbar.


Solution

  • ]you can access navigationBackgroundView

     self.navigationController?.navigationBar.isTranslucent = true
            let navigationBackgroundView = self.navigationController?.navigationBar.subviews.first
            navigationBackgroundView?.alpha = 0.3
    

    enter image description here