gpt4 book ai didi

ios - 为什么设置半透明为背景后ViewController中的Label就没有了?

转载 作者:行者123 更新时间:2023-11-28 14:59:07 24 4
gpt4 key购买 nike

我是 iOS swift 的新手。我尝试将页面从 A 更改为 B,并将页面 B 的背景设置为 alpha 0.5,如下代码所示:

A-ViewController 中:

    @IBAction func btnClick_aitrix_robot(_ sender: Any) {
print("btnClick_aitrix_robot")


let filterVC = QuestionViewController()
filterVC.modalPresentationStyle = UIModalPresentationStyle.custom
self.present(filterVC, animated: true, completion: nil)
}

B-ViewController中:

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
}

page-B 中有一个 Label ,但是我设置半透明后它就消失了页面B的背景。

我错过了什么吗?提前致谢。

最佳答案

我猜您已经在界面生成器中创建了 QuestionViewController View 。并且您有从那里设置消失的 UILabel

如果是这样,那么问题出在您创建 QuestionViewController 的方式上。你需要告诉它从 xib 加载。您可以通过更改:

让 filterVC = QuestionViewController()

对于

let filterVC = UIStoryboard(name: "StoryboardName", bundle: nil).instantiateViewController(withIdentifier: "QuestionViewControllerIdentifier")

请注意,您需要从界面构建器中为 QuestionViewController ViewController 设置标识符。

enter image description here

关于ios - 为什么设置半透明为背景后ViewController中的Label就没有了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49094536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com