I have a view controller which view's background I need to be translucent and keep showing the view below. I've adjusted the opacity in the nib
file and tried both pushing the view controller into a navigation stack and presenting it modally, but when loaded, the previous view is unloaded. How could I solve this?
Just add a Storyboard Segue with Kind set to Present Modally to your modal view controller and on this view controller set the following values: Background = Clear Color. Drawing = Uncheck the Opaque checkbox.
First let us see using storyboard, Open Main. storyboard and add one view to the View Controller. On the right pane you can see the property, and from there update the background color to color you want your view to be as show below.
Is this what you're looking for?
View Controller A -> View Controller B (nib)
Swift < 3:
In View Controller A, add the following line of code:
let viewControllerB = ViewControllerB(nibName: "ViewControllerB", bundle: nil)
viewControllerB.modalPresentationStyle = .OverFullScreen
presentViewController(viewControllerB, animated: true, completion: nil)
And in View Controller B, set the background color of view
with colorWithAlphaComponent
method:
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7)
Swift ≥ 3:
View Controller A:
let viewControllerB = ViewControllerB(nibName: "ViewControllerB", bundle: nil)
viewControllerB.modalPresentationStyle = .overFullScreen
present(viewControllerB, animated: true, completion: nil)
View Controller B:
view.backgroundColor = UIColor.black.withAlphaComponent(0.7)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With