【问题标题】:Swift 5 Xcode 10.3 How to set background transparentSwift 5 Xcode 10.3 如何设置背景透明
【发布时间】:2019-08-30 11:54:24
【问题描述】:

我想创建一个自定义Alert。所以我插入了一个内容UIView,它有一些宽度和高度,剩下的区域我想看起来很暗。

下面的想法我尝试过但没有运气

1- 在Storyboard 我设置背景自定义颜色黑色和opacity 35%。但是几秒钟后背景变黑了。

2- 还尝试使用以下代码在UIViewController 中设置背景不透明度,但不起作用。

view.backgroundColor = UIColor.black.withAlphaComponent(0.35)

任何帮助将不胜感激。提前致谢

【问题讨论】:

  • 我不确定是否有足够的数据来回答它,你能提供更多的代码吗?

标签: ios uiview uiviewcontroller swift5 xcode10.3


【解决方案1】:

将您的 ViewController 显示为 OverCurrentContext 以查看父 viewController

let popupVc : PopupVC = self.storyboard?.instantiateViewControllerWithIdentifier("PopupVC") as! PopupVC
    popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
    self.presentViewController(popupVc, animated: true, completion: nil)

【讨论】:

  • 我用你的代码做了一些改进,现在它工作正常
【解决方案2】:

我想分享对我有用的东西。我正在使用Xcode 10.3Swift 5

第 1 步-Storyboard 我设置了UIView 背景自定义颜色黑色和opacity 35%

第 2 步- 使用下面的代码块呈现 ViewController

let popupVc : VCAlertMPIN = self.storyboard?.instantiateViewController(withIdentifier: "VCAlertMPIN") as! VCAlertMPIN
popupVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(popupVc, animated: true, completion: nil)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-27
    • 2018-12-25
    • 2016-10-09
    • 1970-01-01
    • 2011-06-05
    • 2011-02-02
    • 2011-10-04
    • 2017-03-08
    相关资源
    最近更新 更多