0

Is it possible to have a background image extend into the unsafe areas? I tried the following to set a background image to the Super View and it doesn't work.

// viewDidLoad
override func viewDidLoad() {
    super.viewDidLoad()

    // Set up background image
    let backgroundImage = UIImageView(frame: super.view.bounds)
    backgroundImage.image = UIImage(named: "SpaceBackground")
    backgroundImage.contentMode = UIView.ContentMode.scaleAspectFill
    self.view.insertSubview(backgroundImage, at: 0)

}

This approach uses auto layout.

Ben
  • 3,346
  • 6
  • 32
  • 51

1 Answers1

0

It's not showing up because of the Navigation Controller. Once that is hidden the image covers unsafe background area also.

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.isHidden = true
    }
Ben
  • 3,346
  • 6
  • 32
  • 51