窗口没有出现在模拟中

时间:2015-09-25 15:44:17

标签: ios objective-c

我在xCode 7.1 beta版中将背景颜色设置为绿色,代码如下:

self.window.backgroundColor = [UIColor greenColor] ;
[self.window makeKeyAndVisible];
    NSLog(@"Hello");

我已将此作品放在appdelegate.m的{​​{1}}方法中。

didFinishlaunchingWithOptions正在控制台窗口中打印,但模拟中背景颜色未设置为绿色。

1 个答案:

答案 0 :(得分:0)

要更改背景颜色,您必须在视图控制器中更改视图的背景颜色,而不是在窗口中。您正在更改应用背景颜色,而不是您正在查看的视图背景。

enter image description here

在视图控制器的viewDidLoad

中使用self.view.backgroundColor = [UIColor greenColor];

编辑1:

要查看View Hierarchy调试器,只需运行您的应用程序,然后在任何屏幕上点击Debug View Hierarchy按钮:

enter image description here

相关问题