简体   繁体   English

如何更改UIViewController的背景颜色

[英]How to change background color of UIViewController

I have a MainViewController and it has a container view. 我有一个MainViewController,它有一个容器视图。 with few margin from edges. 边缘的边缘很少。
Now i navigate to another view ViewController1. 现在,我导航到另一个视图ViewController1。 Suppose there i get an error for some region in ViewController1. 假设在ViewController1中某个区域出现错误。 then i want to change my MainViewController's background in red. 然后我想将MainViewController的背景更改为红色。 so the view should look like this(screen shot are attached) where red border is MainViewController Background 所以视图应该看起来像这样(附有屏幕截图),其中红色边框是MainViewController背景

在此处输入图片说明

and here is my code 这是我的代码

class ViewController1: UIViewController {
var MainVC =  MainViewController()
     override func viewDidLoad() {
        super.viewDidLoad()
        MainVC.view.backgroundColor = UIColor.redColor()
    }

but its not working 但它不起作用

尝试这个 :

self.view.backgroundColor = UIColor. greenColor()

You can get any uiviewcontroller object from Navigation controller: 您可以从导航控制器获取任何uiviewcontroller对象:

navigationController?.viewControllers; navigationController?.viewControllers;

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

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