Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting a view controller with dim background

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?

like image 324
AppsDev Avatar asked Jun 06 '16 07:06

AppsDev


People also ask

How do I make my view controller transparent?

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.

How do I change the background color in view controller?

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.


1 Answers

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)
like image 186
Anh Pham Avatar answered Nov 09 '22 23:11

Anh Pham