Search code examples
swiftios8xcode6

UIView background color in Swift


Is there a way to set the UIView background color with Swift?

I know that in Objective-C, you would use self.view.backgroundColor = [UIColor redColor];, but that does not work the same way in Swift. I have looked around and because Swift is only about a week old, I cannot find an answer.

Does anyone have any suggestions?


Solution

  • self.view.backgroundColor = UIColor.redColor()
    

    In Swift 3:

    self.view.backgroundColor = UIColor.red