Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift ViewController Background getting black with alpha

I'm calling a ViewController as popover when the user presses a button. The View should have black background with alpha 0.5. But the View is shown as that for a second, than the whole background turns black without alpha. Any idea why?

Thats my popover call:

let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
    popOver.modalPresentationStyle = .popover
    self.present(popOver, animated: true, completion: nil)

I'm trying to set the background color in popovers viewDidLoad() function with following code:

self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
like image 603
Philipp Rosengart Avatar asked Jan 04 '17 11:01

Philipp Rosengart


1 Answers

For that set modalPresentationStyle to overCurrentContext instead of popover.

let popOver = storyboard?.instantiateViewController(withIdentifier: "popOver") as! ViewControllerPopOver
popOver.modalPresentationStyle = .overCurrentContext
self.present(popOver, animated: true)
like image 50
Nirav D Avatar answered Nov 15 '22 18:11

Nirav D