gpt4 book ai didi

ios - 从 ViewController 调用时如何设置应用程序的 UIWindow 颜色

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:35 24 4
gpt4 key购买 nike

在 App delegate 中,可以设置应用程序的 UIWindow 颜色,如代码所示。

但是,当尝试将应用程序的 UIWindow 颜色设置为 ViewController 中的不同颜色时,例如调用 self.window?.backgroundColor = UIColor.blueColor() 被忽略。没有错误发生,但也没有发生颜色变化。

问题:

1 - 在 ViewController 中调用应用程序时如何设置它的窗口颜色?注意:我不是要更改 View 背景颜色,而是要更改位于 View 后面的 UIWindow 颜色。

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

self.window?.backgroundColor = UIColor.redColor()

return true

}

}

最佳答案

尝试通过您的 AppDelegateUIApplication 类访问窗口:

if let window = (UIApplication.sharedApplication().delegate?.window)! as UIWindow! {
window.backgroundColor = UIColor.redColor()
}

if let window = UIApplication.sharedApplication().windows.first as UIWindow! {
window.backgroundColor = UIColor.redColor()
}

关于ios - 从 ViewController 调用时如何设置应用程序的 UIWindow 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35920020/

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