Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a variant of the AF <code>UIImageView</code> category that calls a block when the asynchronous image request is complete. </p> <p>You can resize the returned image in the success block and assign it to the image view. See </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 </code></pre> <p>Once the image has been resized, make sure you assign the image to the <code>UIImageView</code> on the main queue using GCD as the block will be called in a background thread. </p> <p>Here's an example using a UIIImageView with its content mode set to AspectFill. Resizing using Core Graphics will usually look better than having the UIImageView rescale the image. </p> <pre><code>__weak typeof(self) weakSelf = self; CGSize targetSize = self.targetImageView.bounds.size; [self.targetImageView setImageWithURL:photoURL success:^(UIImage *image) { CGFloat imageHeight = image.size.height; CGFloat imageWidth = image.size.width; CGSize newSize = targetSize; CGFloat scaleFactor = targetSize.width / imageWidth; newSize.height = imageHeight * scaleFactor; UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; UIImage *small = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); dispatch_async(dispatch_get_main_queue(),^ { weakSelf.targetImageView.image = small; }); } failure:^(NSError *error) { // Handel the error here }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload