开发者

self.view.backgroundColor = [UIColor greenColor]; does not work in pushed view

开发者 https://www.devze.com 2023-04-07 09:02 出处:网络
I want to draw something in drawRect of pushed view. Also, I want to change ba开发者_如何学Pythonck ground color of view.

I want to draw something in drawRect of pushed view. Also, I want to change ba开发者_如何学Pythonck ground color of view.

I can change background color by self.view.backgroundColor = [UIColor greenColor]; in viewDidLoad, if view is main view.

I used that in viewDidLoad of pushed view controller, but it is still black.

MyViewController *myViewController = [MyViewController alloc]init];
[self.navigationContoller pushViewController:myViewContoller animated:YES]; // I want to change background color of this view.
[myViewController release];


Setting the myViewController's background color before pushing it should work.

myViewController.view.backgroundColor = [UIColor greenColor];
// push myViewController.

Or you can go to the viewWillAppear of that view and set the backgroundColor there.


In Apple Swift, We can use:

self.view.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 1)

Background will change to Green


You actually should customize your view in viewDidLoad of your pushed view. Thats what it is made for.

0

精彩评论

暂无评论...
验证码 换一张
取 消