iosuiviewuiviewcontrollerswift5xcode10.3

Swift 5 Xcode 10.3 How to set background transparent


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


Solution

  • 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