Search code examples
iosswiftbackground

How to set a background image in Xcode using swift?


How can I set a background image for my main view controller in Xcode 6 using swift? I know that you can do this in the assistant editor as below:

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = UIColor.yellowColor()
}

What is the code to set the background to an image I have in my assets folder?


Solution

  • override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))
    }