Declared in UIImageView+AFNetworking.h
UIImageView+AFNetworking.m

Overview

This category adds methods to the UIKit framework’s UIImageView class. The methods in this category provide support for loading remote images asynchronously from a URL.

Properties

imageResponseSerializer

The response serializer used to create an image representation from the server response and response data. By default, this is an instance of AFImageResponseSerializer.

@property (nonatomic, strong) AFImageResponseSerializer<AFURLResponseSerialization> *imageResponseSerializer

Discussion

Subclasses of AFImageResponseSerializer could be used to perform post-processing, such as color correction, face detection, or other effects. See https://github.com/AFNetworking/AFCoreImageSerializer

Declared In

UIImageView+AFNetworking.h

Class Methods

setSharedImageCache:

Set the cache used for image loading.

+ (void)setSharedImageCache:(id<AFImageCache>)imageCache

Parameters

imageCache

The image cache.

Declared In

UIImageView+AFNetworking.h

sharedImageCache

The image cache used to improve image loadiing performance on scroll views. By default, this is an NSCache subclass conforming to the AFImageCache protocol, which listens for notification warnings and evicts objects accordingly.

+ (id<AFImageCache>)sharedImageCache

Declared In

UIImageView+AFNetworking.h

Instance Methods

cancelImageRequestOperation

Cancels any executing image operation for the receiver, if one exists.

- (void)cancelImageRequestOperation

Declared In

UIImageView+AFNetworking.h

setImageWithURL:

Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.

- (void)setImageWithURL:(NSURL *)url

Parameters

url

The URL used for the image request.

Discussion

If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.

By default, URL requests have a Accept header field value of “image / *”, a cache policy of NSURLCacheStorageAllowed and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use setImageWithURLRequest:placeholderImage:success:failure:

Declared In

UIImageView+AFNetworking.h

setImageWithURL:placeholderImage:

Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage

Parameters

url

The URL used for the image request.

placeholderImage

The image to be set initially, until the image request finishes. If nil, the image view will not change its image until the image request finishes.

Discussion

If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.

By default, URL requests have a Accept header field value of “image / *”, a cache policy of NSURLCacheStorageAllowed and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use setImageWithURLRequest:placeholderImage:success:failure:

Declared In

UIImageView+AFNetworking.h

setImageWithURLRequest:placeholderImage:success:failure:

Asynchronously downloads an image from the specified URL request, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.

- (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

Parameters

urlRequest

The URL request used for the image request.

placeholderImage

The image to be set initially, until the image request finishes. If nil, the image view will not change its image until the image request finishes.

success

A block to be executed when the image request operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the request and response parameters will be nil.

failure

A block object to be executed when the image request operation finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.

Discussion

If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.

If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with self.image = image is applied.

Declared In

UIImageView+AFNetworking.h