title: How to resize UIImage created with resizableImageWithCapInsets when used for an UIImageView / UIView
body: <p>I'm writing code to use a custom image as the background for a <code>UIView</code>.</p>
  
  <p>The app runs in portrait only. Prior to the 4" retina screen, I used fixed size, hand-drawn png as the background image (<code>card.png</code> below). I had code like this:</p>
  
  <pre><code>UIView* frontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
  frontView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  
  UIImage* cardImage = [UIImage imageNamed:@"card.png"];
  UIImageView* im = [[UIImageView alloc] initWithImage:cardImage];
  im.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
  [frontView addSubview:im];
  
  // frontView has a bunch of stuff added...
  </code></pre>
  
  <p>As you'd expect, when I run this on an iPhone 5, everything can be dynamically sized and positioned, except for the hand drawn png, <code>card.png</code>. So that background image isn't using the full height that is available...</p>
  
  <p>So what (I think) I want to do, is something like this...</p>
  
  <pre><code>UIImage* cardImage = [[UIImage imageNamed:@"card_resizable.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(72, 0, 60, 0)];
  </code></pre>
  
  <p>I've redrawn <code>card.png</code> as <code>card_resizable.png</code> - it's 140 pixels in height, there's an 8 pixel chunk in the middle, which I want to tile, so the top inset is 72 pixels tall and the bottom inset is 60 pixels tall.</p>
  
  <p>What's the next step?</p>
  
  <p>Should I create the <code>UIImageView</code> with the dynamic size of <code>frontView</code>?</p>
  
  <p>How do I make the resizable image, resize?</p>
  
  <p>The few things that I've tried... none of them have resulted in tiling the resizable image.</p>
  
  <p>Cheers,
  Gavin</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I was incorrectly setting the pixel values for <code>UIEdgeInsetsMake(72, 0, 60, 0)</code>
  These values are based on the <code>@2x</code> image. When changed to <code>UIEdgeInsetsMake(36, 0, 30, 0)</code> - I get the correct, vertical resizing.</p>
  
  <p>As Mike pointed out, I needed to set the size of the <code>UIImageView</code> to the parent, and correctly set it's <code>autoresizingMask</code>:</p>
  
  <p><code>im.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;</code></p>
  
  <p>I know have the <code>UIImageView</code> sized dynamically sized, correctly, to fill its parent view - <code>frontView</code> (I've given it a green background to check visually on both 3.5" screen and 4" screen.</p>
  
  <p>The resizable image, <code>cardImage</code>, is also resizing, correctly, in the vertical plane.</p>