SwiftER
SwiftER

Reputation: 1255

Swift Navigation Controller View with transparent background

How can I present a UINavigationController with a transparent Background. A regular view without the navigation bar works fine, but when I add the navigationBar to the same code I get a black screen instead of .clear

primary view Controller

let vc = NewRquestViewController()
        vc.modalPresentationStyle = .overCurrentContext
        vc.mapView = self.mapView
        let nvc = UINavigationController(rootViewController:vc)

        self.present(nvc, animated: true, completion: nil)

second view

view.isOpaque = false
        self.view.backgroundColor = .clear

Upvotes: 2

Views: 2119

Answers (1)

anckydocky
anckydocky

Reputation: 76

That black screen you're getting when you're setting the color to .clear is the UIWindow because the navigationBar doesn't have the background you're imagining. It is the first layer - same as the first view you are putting for the background - and therefore, setting the background color to .clear will result in a black color.

My solution was to replace the navigationController with a navBar (I did the navigation between controllers using segue) and set it's style to default, checked the translucent box and also set the alpha to be 0.2 or something like that, the only problem I also have to solve is that the alpha is affecting the navigationItem and I have no idea how to deal with that. If I'll find a solution, I'll let you know.

Upvotes: 2

Related Questions