在函数Appdelegate中 - didFinishLaunchingWithOptions实现:
var testView : UIView = UIView(frame: CGRectMake(100, 100, 100, 100))
testView.backgroundColor = UIColor.blueColor()
self.window?.addSubview(testView)
self.window?.bringSubviewToFront(testView)
self.window?.makeKeyAndVisible()
但不显示testView。
答案 0 :(得分:3)
您需要做的只是为您的窗口提供框架。
,您的代码将是:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
var testView : UIView = UIView(frame: CGRectMake(0 , 0, 100, 100))
testView.backgroundColor = UIColor.blueColor()
self.window?.addSubview(testView)
self.window?.bringSubviewToFront(testView)
self.window?.makeKeyAndVisible()