change the uiview background color with code
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
self.view.backgroundColor = [UIColor redColor];
possible colors are :
blackColor
darkGrayColor
lightGrayColor
whiteColor
grayColor
redColor
greenColor
blueColor
cyanColor
yellowColor
magentaColor
orangeColor
purpleColor
brownColor
clearColor
For Swift 3, you should do:
self.view.backgroundColor = UIColor.white
Unfortunately, the other answers no longer work in Swift 3.
If you want to change the background color of the view with code in Swift, you should do instead:
self.view.backgroundColor = UIColor.redColor();