Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the uiview background color with code

I would like to change the background color of my app programmatically, not IB. Is it possible to get both a Swift and Obj-C answer.

like image 396
Rafael Avatar asked Sep 11 '25 05:09

Rafael


1 Answers

You can set the backgroundColor property of whatever view it is you have on screen.

In Objective-C:

self.view.backgroundColor = [UIColor redColor];

In Swift:

self.view.backgroundColor = .red

or if it's the main window you're after,

In Objective-C:

self.window.backgroundColor = [UIColor redColor];

In Swift:

self.window.backgroundColor = .red
like image 125
Jamie Avatar answered Sep 12 '25 21:09

Jamie