How to set a background image in Xcode using swift?

GuiGui23 picture GuiGui23 · Nov 20, 2014 · Viewed 134.5k times · Source

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?

Answer

Hayley Guillou picture Hayley Guillou · Nov 20, 2014
override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))
}