title: Change the size of UIButton’s imageView
body: <p>I am working on a subclass of <code>UIButton</code>, let’s call it <code>MyButton</code>. In most cases, buttons of this subclass will have both image and title.</p>
  
  <p>I am having troubles configuring <code>MyButton</code>’s <code>imageView</code> size. <strong>The goal is to limit the size of the image, so that larger images are resized and fit into a 32-by-32 square.</strong></p>
  
  <p><em>For testing purposes, I added a 128-by-128-pixel image, and set <code>imageView</code>’s <code>backgroundColor</code> to <code>green</code>.</em></p>
  
  <p>Below is what the button looked like when I added the image. Both the <code>imageView</code> and its <code>image</code> had the size of 128 by 128 pixels.</p>
  
  <p><img src="https://i.stack.imgur.com/ZqyMt.png" alt="Button with the original-size image"></p>
  
  <p>After I overrode <code>MyButton</code>’s <code>intrinsicContentSize</code> with <code>CGSize(width: 160, height: 50)</code> and set the button’s <code>imageView</code>’s <code>contentMode</code> to <code>.scaleAspectFit</code>, the <code>imageView</code> resized, but only in height—it’s still 128 pixels wide, which causes the button’s title to truncate.</p>
  
  <p><img src="https://i.stack.imgur.com/UoQUT.png" alt="Button with reduced height but original width"></p>
  
  <p>I’ve seen a lot of articles on how to resize the <code>image</code> inside the <code>imageView</code> using <code>imageEdgeInsets</code>. <strong>This is not what I am looking for</strong> since in all those articles the <code>imageView</code> preserves its size and only adds padding around the image.</p>
  
  <p>Changing the <code>imageView</code>’s <code>frame</code> or <code>bounds</code> produces no result.</p>
  
  <p>Any thoughts on how I can resize the button’s <code>imageView</code>?</p>