title: How to center an image inside an UIButton without stretching in both direction in Swift?
body: <p>I am making a custom keyboard and I need to centre the image of the shift icon inside the shift button. The image is 100px x 100px. </p>
  
  <p>However, the button frame in portrait is <code>36pt x 38pt</code>, and in landscape, it is <code>68pt x 32pt</code>. I have tried using button image inset property to centre the image. However, it does not does so.</p>
  
  <p>I tried myself and set the image edge insets to <code>(25,25,25,25)</code>, the image centres in both sizes. However, the icon becomes too small to see.</p>
  
  <pre><code>shiftButton.setImage(UIImage(named: "shift"), forState: .Normal)
  
  shiftButton.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,0)
  </code></pre>
  
  <p>I am making the button programatically. And, I need the button to scale maintaining its aspect ratio i.e. <code>1:1</code>. Its maximum width or height is always tied to the button's height itself. The image width/height should be maximum of button's height. And, it should not stretch in any way to distort the icon. However, the button itself can stretch.</p>
  
  <p>I need the image to scale according to button frame but maintain its aspect ratio. And, it can down scale or up scale, but should always maintain the 1:1 aspect ratio.</p>
  
  <p>Any suggestions for solving this problem?</p>