How can I get an image to fit the whole screen?

1.4k views Asked by At

I'm new to Swift, and I'm trying to make an image in a tabbed application fill the whole screen. This is what I've got so far.

 let imageName = "bkgrd"
    let image = UIImage(named: imageName)
    let imageView = UIImageView(image: image!)

    imageView.frame = CGRect( 0, 0, 100, 200)

However this doesn't seem to work, could anyone help?

1

There are 1 answers

0
Audrey Li On BEST ANSWER

You can add a imageView directly from interface builder, and set the autolayout constraints to superview to 0 and the image source, or you can add programmatically as below:

  let imageView = UIImageView(frame: view.bounds)
    imageView.image = UIImage(named: "bkgrd")
    view.addSubview(imageView)