Reputation: 1284
I want to create a custom Alert
. So I inserted a content UIView
with some width and height and the remaining area I want to look dim.
Below ideas I've tried but no luck
1- In Storyboard
I set background custom color black and opacity
35%. But After a few second background is turning black.
2- Also tried to set background opacity in UIViewController
by using below code, but not working.
view.backgroundColor = UIColor.black.withAlphaComponent(0.35)
any help would be appreciated. Thanks in advance
Upvotes: 1
Views: 1614
Reputation: 847
Present your ViewController as OverCurrentContext
to see parent viewController
let popupVc : PopupVC = self.storyboard?.instantiateViewControllerWithIdentifier("PopupVC") as! PopupVC
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.presentViewController(popupVc, animated: true, completion: nil)
Upvotes: 3
Reputation: 1284
I would like to share what worked for me. I am using Xcode 10.3
and Swift 5
Step 1- In Storyboard
I set UIView
background custom color black and opacity 35%
.
Step 2- Presented the ViewController
using the bellow chunk of code.
let popupVc : VCAlertMPIN = self.storyboard?.instantiateViewController(withIdentifier: "VCAlertMPIN") as! VCAlertMPIN
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(popupVc, animated: true, completion: nil)
Upvotes: 1