我想创建一个自定义的 Alert
。因此,我插入了一个内容 UIView
,其中包含一些宽度和高度,其余区域我希望看起来暗淡。
下面是我尝试过但没有成功的想法
1- 在 Storyboard
中,我将背景自定义颜色设置为黑色和 不透明度
35%。但是几秒钟后背景变黑了。
2- 还尝试使用以下代码在 UIViewController
中设置背景不透明度,但不起作用。
view.backgroundColor = UIColor.black.withAlphaComponent(0.35)
如有任何帮助,我们将不胜感激。提前致谢
最佳答案
将您的 ViewController 呈现为 OverCurrentContext
以查看父 viewController
let popupVc : PopupVC = self.storyboard?.instantiateViewControllerWithIdentifier("PopupVC") as! PopupVC
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.presentViewController(popupVc, animated: true, completion: nil)
关于ios - Swift 5 Xcode 10.3 如何设置背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57726265/