title: How to resize UIImageView by image size in Swift
body: <p>I want to increase the image using the zoom. I did this and did that would be equal to the size of the type size of the image but I still background with top like this change? How can I make it?</p>
  
  <p>My imageView in viewDidLoad</p>
  
  <pre><code>    imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
      imageView.backgroundColor = .greenColor()
      imageView.image = UIImage(contentsOfFile: document.documentImageURL)
      imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] //
  
  
     func setZoomScale() {
      let widthRatio = imageView.bounds.size.width / (imageView.image?.size.width)!
      let heightRatio = imageView.bounds.size.height / (imageView.image?.size.height)!
      let scale = min(widthRatio, heightRatio)
      let imageWidth = scale * (imageView.image?.size.width)!
      let imageHeight = scale * (imageView.image?.size.height)!
      imageView.frame = CGRect(x: 0, y: 0, width: imageWidth, height: imageHeight)
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uUW0g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uUW0g.jpg" alt="enter image description here"></a></p>