简体   繁体   English

以编程方式更改UIView背景颜色

[英]Change UIView background color programmatically

I've just created a new view based application, and now I want to set the background color at the application startup rather then in IB. 我刚刚创建了一个基于视图的新应用程序,现在我想在应用程序启动时而不是在IB中设置背景颜色。 I have found this code in a tutorial: 我在教程中找到了这段代码:

UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[view setBackgroundColor:[UIColor greenColor]];

But my view is still white. 但我的观点仍然是白色的。

How do I make it work? 我如何使其工作?

Thanks in advance. 提前致谢。

This should work. 这应该工作。 Are you adding the view to the window using addSubView ? 您是否使用addSubView将视图添加到窗口?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM