[英]Swift 5 Xcode 10.3 How to set background transparent
I want to create a custom Alert
.我想创建一个自定义
Alert
。 So I inserted a content UIView
with some width and height and the remaining area I want to look dim.所以我插入了一个具有一些宽度和高度的内容
UIView
以及我想要看起来暗淡的剩余区域。
Below ideas I've tried but no luck以下是我尝试过但没有运气的想法
1 - In Storyboard
I set background custom color black and opacity
35%. 1 - 在
Storyboard
我将背景自定义颜色设置为黑色和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. 2-还尝试使用以下代码在
UIViewController
设置背景不透明度,但不起作用。
view.backgroundColor = UIColor.black.withAlphaComponent(0.35)
any help would be appreciated.任何帮助,将不胜感激。 Thanks in advance
提前致谢
Present your ViewController as OverCurrentContext
to see parent viewController将您的 ViewController 显示为
OverCurrentContext
以查看父 viewController
let popupVc : PopupVC = self.storyboard?.instantiateViewControllerWithIdentifier("PopupVC") as! PopupVC
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.presentViewController(popupVc, animated: true, completion: nil)
I would like to share what worked for me.我想分享对我有用的东西。 I am using
Xcode 10.3
and Swift 5
我正在使用
Xcode 10.3
和Swift 5
Step 1- In Storyboard
I set UIView
background custom color black and opacity 35%
.步骤 1-在
Storyboard
我将UIView
背景自定义颜色设置为黑色和opacity 35%
。
Step 2- Presented the ViewController
using the bellow chunk of code.第 2 步 -使用下面的代码块展示了
ViewController
。
let popupVc : VCAlertMPIN = self.storyboard?.instantiateViewController(withIdentifier: "VCAlertMPIN") as! VCAlertMPIN
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(popupVc, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.