0

I write this code in xcode8 but i have Error :

 if let window = UIApplication.sharedApplication.keywindow{
            let blackView = UIView()
            blackView.backgroundColor = UIColor.black

            window.addSubview(blackView)
            blackView.frame = view.frame
        }

but i have error that UIApplication has no member keywindow

what should i do !?

2 Answers2

0

after a lot of search at the end i find it how to solve :

if let window = UIApplication.shared.delegate?.window {
            let blackView = UIView()
            blackView.backgroundColor = UIColor.black
            window?.addSubview(blackView)
            blackView.frame = (window?.frame)!

        }

SOLVE:

shared.delegate.window

instead of

sharedApplication.keywindow

and

blackView.frame = window.frame

Change it to

blackView.frame = (window?.frame)!
0

Solve : (Swift 3)

if let window = UIApplication.shared.keyWindow {
            let blackView = UIView()
            blackView.backgroundColor = UIColor.black

            window.addSubview(blackView)
            blackView.frame = window.frame
}
Pranavan SP
  • 1,785
  • 1
  • 17
  • 33