How to make the UIView to cover the whole screen. I have a black UIView and it's alpha value is 0.5. It has a subview on it as well. Right now the blackView is below the navigationBar. I want it to cover the whole screen including navigationBar.
As you can see in the picture below. The dark view behind the popup view should cover the whole screen. The constraints I am using for the view is simply:
view.addsubView(blackView)
_ = blackview.anchor(view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 0)
The pop up window is a subview of the blackView:
blackView.addSubview(reminderPopUpView)
How can I do this?
You can simply add your black view as a window subview.
UIApplication.shared.keyWindow?.addSubview(blackView)
Follow below steps to resolve your problem:
1> Create your UIView
with outlet you want to overlay lets call it viewOverLay
2> Use this below code to overlay that view to cover whole screen even navigation bar
self.navigationController?.view.addSubview(self.viewOverLay)
self.viewOverLay.frame.size.height = (self.navigationController?.view.bounds.height)!
self.viewOverLay.alpha = 0.0
3> When you want to show it
UIView.animate(withDuration: 0.3) { self.viewOverLay.alpha = 1.0 }
4> When you want to hide it
UIView.animate(withDuration: 0.3) { self.viewOverLay.alpha = 0.0 }
Please let me know if it works for you.
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