title: UIImageView, setClipsToBounds and how my images are losing their head
body: <p>I'm developing an iOS 4 application.</p>
  
  <p>I'm using this code on an <code>UIImageView</code> on an <code>UITableViewCell</code>:</p>
  
  <pre><code>cell.photo.contentMode = UIViewContentModeScaleAspectFill;
  [cell.photo setClipsToBounds:YES];
  </code></pre>
  
  <p>My images are taller than wide, and when I set <code>UIViewContentModeScaleAspectFill</code>, images are scaled to fit width with UIImageView width. Doing this, the image gets bigger that UIImageView and I see it outside <code>UIImageView</code>.</p>
  
  <p>Then, I need to use <code>setClipsToBounds:YES</code> to don't allow this, but now all my images lose their head.</p>
  
  <p>Is there any way to use UIViewContentModeScaleAspectFill and center top left image corner with top left <code>UIImageView</code> corner? If I need to lose a part of image, I prefer to lose its feet that its head.</p>
  
  <p><strong>UPDATE</strong><br/><br/></p>
  
  <p>I'm using <a href="https://github.com/rs/SDWebImage" rel="noreferrer">sdWebImage</a> framework and I have used Vadim Yelagin answer and this is my code now:</p>
  
  <pre><code>[cell.photo setImageWithURL:[NSURL URLWithString:entry.photo]
                 placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                          success:^(UIImage *image) {
                              CGFloat scaleX = cell.photoBorder.bounds.size.width / image.size.width;
                              CGFloat scaleY = cell.photoBorder.bounds.size.height / image.size.height;
                              CGFloat scale = MAX(scaleX, scaleY);
                              cell.photo.frame = CGRectMake(0, 0, image.size.width * scale, image.size.height * scale);
                              cell.photo.image = image;
                          } 
                          failure:nil];
  </code></pre>
  
  <p>I have to wait to get all images loaded and reload move around UITableView to see the right image on the right cell (this is because images are cached and it loads faster).</p>
  
  <p>Instead using <code>cell.photo.frame</code> and <code>cell.photo.image</code> I need to pass to block <code>indexPath.row</code> to get the right cell.</p>
  
  <p>I could add a new method to UIImageView+WebCache:</p>
  
  <pre><code>- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder success:(void (^)(UIImage *image, NSInteger row))success failure:(void (^)(NSError *error))failure;
  {
      [self setImageWithURL:url placeholderImage:placeholder options:0 success:success failure:failure];
  }
  </code></pre>
  
  <p>But if I do that, I get an error here:</p>
  
  <pre><code>[self setImageWithURL:url placeholderImage:placeholder options:0 success:success failure:failure];
  </code></pre>
  
  <p>Because now success isn't of type <code>(void (^)(UIImage *image))</code></p>
  
  <p>Do you know how can I fix this problem?</p>