1

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?

fusion
  • 27
  • 6
  • possible duplicate of [Makeing view resize to its parent when added with addSubview](http://stackoverflow.com/questions/1750256/makeing-view-resize-to-its-parent-when-added-with-addsubview) – Literphor Jun 07 '15 at 16:46
  • In your example you're setting the width to 100 pixels and height to 200 pixels. – Literphor Jun 07 '15 at 16:47
  • What's the proper width/height it should be set to? – fusion Jun 07 '15 at 16:49

1 Answers1

2

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)
Audrey Li
  • 980
  • 2
  • 11
  • 14