title: Swift UIImageView Stretched Aspect
body: <p>UIImageView renders the size of an image incorrectly. Using Scale Aspect Fit, if the UIImageView is a square the image is the correct aspect ratio with transparency in the areas the image does not fill.</p>
  
  <pre><code>//Image is Square &amp; Correct Size
  var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 320))
  imageView.clipsToBounds = true
  imageView.contentMode = UIViewContentMode.ScaleAspectFit
  
  //Image is Rectangle &amp; Incorrect Size
  var imageView = UIImageView(frame: CGRectMake(0, 50, 320, 450))
  imageView.clipsToBounds = true
  imageView.contentMode = UIViewContentMode.ScaleAspectFit
  </code></pre>
  
  <p>The UIImageView needs to touch the edges and have transparent space at the top and bottom of the screen and the image inside needs to keep its original ratio rather than stretching taller. I have attached two images of how the image inside the UIImageView is rendering.</p>
  
  <p><img src="https://i.stack.imgur.com/jckO8.jpg" alt="ImageView with correct Aspect">
  <img src="https://i.stack.imgur.com/SFjll.jpg" alt="ImageView with wrong Aspect"></p>