title: Resize UIImage in in asynchronous mode, using AFNetworking
body: <p>I am using AFNetwork in my application to get some data from my web service.
  In these data, there are some images with random sizes, I need to add some UIImageView.</p>
  
  <p>My problem is to <strong>adjust the image in the correct scale</strong> of UIImageView, in asynchronous mode.</p>
  
  <p>Any idea how to do this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am using the normal method of the Afnetwoking´s projects:</p>
  
  <pre><code> [self setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"img_my_nophoto"]];
  </code></pre>
  
  <p>The logic inside this method is :</p>
  
  <pre><code>- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 
            placeholderImage:(UIImage *)placeholderImage 
                     success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
                     failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
  {
      [self cancelImageRequestOperation];
  
  UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
  if (cachedImage) {
      self.image = cachedImage;
      self.af_imageRequestOperation = nil;
  
      if (success) {
          success(nil, nil, cachedImage);
      }
  } else {
      self.image = placeholderImage;
  
      AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
      [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
          if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
              self.image = responseObject;
              self.af_imageRequestOperation = nil;
          }
  
          if (success) {
              success(operation.request, operation.response, responseObject);
          }
  
          [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
  
  
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
              self.af_imageRequestOperation = nil;
          }
  
          if (failure) {
              failure(operation.request, operation.response, error);
          }
  
      }];
  
      self.af_imageRequestOperation = requestOperation;
  
          [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];
      }
  }
  </code></pre>
  
  <p>The full class code:
  <a href="https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/UIImageView%2BAFNetworking.m" rel="nofollow">https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/UIImageView%2BAFNetworking.m</a></p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I solve my problem setting the UIImageView with</p>
  
  <p>self.contentMode = UIViewContentModeScaleAspectFill;</p>
  
  <p>self.clipsToBounds=YES;</p>
  
  <p>basically this set the image with the proper scale, and cut all the edges..</p>