gpt4 book ai didi

swift - 如何在 Swift 中设置 UIWindow 属性

转载 作者:行者123 更新时间:2023-11-28 10:02:44 25 4
gpt4 key购买 nike

我一直在尝试对 Swift 中的 UIWindow 边界进行简单的更改。到目前为止,我有:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:NSDictionary?) -> Bool {
// Override point for customization after application launch.


//SHIFT EVERYTHING DOWN - THEN UP IN INDIV VCs IF ios7>
var device:UIDevice=UIDevice()
var systemVersion:String=device.systemVersion
println(systemVersion)
//Float(systemVersion)

if (systemVersion >= "7.0") {
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
self.window.setClipsToBounds = true // --> Member doesnt exist in UIWindow
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height);
self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height);
//}

let ok = true
println("Hello World")
return true
}

但我得到:

UIWindow 没有在每个 self.window.property setter 行命名的成员。

最佳答案

问题是 self.window 是可选的。你首先要"unwrap" it .您还需要使用 clipsToBounds 而不是 setClipsToBounds

if let window = self.window {
window.clipsToBounds = true
window.frame = CGRect(x: 0, y: 20, width: window.frame.size.width, height: window.frame.size.height);
window.bounds = CGRect(x: 0, y: 0, width: window.frame.size.width, height: window.frame.size.height);
}

注意:我还将 CGRectMake 更新为使用 CGRect 初始值设定项而不是全局 CGRectMake 函数创建 CGRect 的首选 Swift 方式。

关于swift - 如何在 Swift 中设置 UIWindow 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24254044/

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