Swift 5 Xcode 10.3 How to set background transparent

1.5k Views Asked by At

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

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

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)

enter image description here

1
On

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)