首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在swift5中显示模态屏幕?

如何在swift5中显示模态屏幕?
EN

Stack Overflow用户
提问于 2019-09-20 10:11:22
回答 1查看 184关注 0票数 1

我目前正在从事iOS项目。

我的问题是,当我看到新的屏幕,我没有看到旧的屏幕,我只看到新的屏幕。

我想要一个模态屏幕。我遗漏了什么?

move ModalScreen

代码语言:javascript
复制
    func callAlert(_ text: String!) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let myAlert = storyboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
        myAlert.modalPresentationStyle = .overCurrentContext
        myAlert.modalTransitionStyle = .crossDissolve
        myAlert.text = text
        self.present(myAlert, animated: false, completion: nil)
    }

modalScreenController

代码语言:javascript
复制
class ModalViewController : UIViewController {

    var text: String?


    @IBOutlet weak var modalCustomAlert: UITextView!
    @IBOutlet weak var okButton: UIButton!

    @IBAction func okPress(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        modalCustomAlert.layer.cornerRadius = 8
        self.modalCustomAlert.text = text
    }
...

modalStoryBoard

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-20 11:06:06

您需要在视图控制器的视图中设置带有alpha组件的背景色。

代码语言:javascript
复制
class ModalViewController : UIViewController {

    var text: String?


    @IBOutlet weak var modalCustomAlert: UITextView!
    @IBOutlet weak var okButton: UIButton!

    @IBAction func okPress(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5) //Your desired color and alpha component
        modalCustomAlert.layer.cornerRadius = 8
        self.modalCustomAlert.text = text
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58026299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档