Declared in UIImageView+AFNetworking.h

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.

Tasks

Accessing Image Cache

  • + sharedImageCache

    The image cache used to improve image loading 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.

  • + setSharedImageCache:

    Set the cache used for image loading.

Accessing Response Serializer

Setting Image

Properties

imageResponseSerializer

@property (nonatomic, strong) id<AFURLResponseSerialization> imageResponseSerializer
Discussion

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

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:

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

Set the cache used for image loading.

Parameters

imageCache

The image cache.

Declared In

UIImageView+AFNetworking.h

sharedImageCache

+ (id<AFImageCache>)sharedImageCache
Discussion

The image cache used to improve image loading 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.

Declared In

UIImageView+AFNetworking.h

Instance Methods

cancelImageRequestOperation

- (void)cancelImageRequestOperation
Discussion

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

Declared In

UIImageView+AFNetworking.h

setImageWithURL:

- (void)setImageWithURL:(NSURL *)url
Discussion

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.

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:

Parameters

url

The URL used for the image request.

Declared In

UIImageView+AFNetworking.h

setImageWithURL:placeholderImage:

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

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.

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:

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.

Declared In

UIImageView+AFNetworking.h

setImageWithURLRequest:placeholderImage:success:failure:

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

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.

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.

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.

Declared In

UIImageView+AFNetworking.h