title: Change size of UIImageView to fit different UIImages
body: <p>So I have my UIImageView which is called <code>imgView</code>. Basically the user can add his own images to this view and save it again to his own gallery.</p>
  
  <p>Because I don't know beforehand what the sizes the images from the User are the <code>imgView</code> should change it's size everytime to perfectly fit the image with aspectFit. If the image is small the <code>imgView</code> shrinks so it doesn't take up much space etc. </p>
  
  <p>I have used this code in my <code>viewDidLoad</code> to achieve it but it doesn't do anything: </p>
  
  <pre><code>imgView.frame.size.width = imgView.image?.size.width
  imgView.frame.size.height = imgView.image?.size.height
  </code></pre>
  
  <p>or</p>
  
  <pre><code>imgView.bounds.size = imgView.image?.size
  </code></pre>
  
  <p>What should I do differently?</p>
  
  <p>Edit for alexburtnik's answer:</p>
  
  <p>This is my code now:
  <a href="https://i.stack.imgur.com/FEBPr.png" rel="nofollow"><img src="https://i.stack.imgur.com/FEBPr.png" alt=""></a></p>
  
  <p>In the Simulator:</p>
  
  <p><a href="https://i.stack.imgur.com/ajs0t.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/ajs0t.jpg" alt="enter image description here"></a></p>
  
  <p>I changed the background in my Image View to green. So right now it fills out the whole screen but it the view shouldn't be larger than the image itself.</p>