【问题标题】:window can't addsubview with swift窗口无法快速添加子视图
【发布时间】:2015-04-24 09:21:12
【问题描述】:

在函数 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。

【问题讨论】:

标签: swift window appdelegate addsubview


【解决方案1】:

您需要做的就是为您的窗口添加框架。

您的代码将是:

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()

【讨论】:

  • TestView 显示正常,但屏幕为黑色,我需要将 testView 带入导航控制器的字体中。 (testView 是页脚底部)。 tks!
  • 你的问题是如何显示测试视图。您没有提及其他任何内容。如果可行,请接受答案..:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多