UIButton(AFNetworking) Category Reference
Declared in | UIButton+AFNetworking.h UIButton+AFNetworking.m |
Overview
This category adds methods to the UIKit framework’s UIButton
class. The methods in this category provide support for loading remote images and background images asynchronously from a URL.
Tasks
Setting Image
-
– setImageForState:withURL:
-
– setImageForState:withURL:placeholderImage:
-
– setImageForState:withURLRequest:placeholderImage:success:failure:
Setting Background Image
-
– setBackgroundImageForState:withURL:
-
– setBackgroundImageForState:withURL:placeholderImage:
-
– setBackgroundImageForState:withURLRequest:placeholderImage:success:failure:
Canceling Image Loading
Instance Methods
cancelBackgroundImageRequestOperation
Cancels any executing background image operation for the receiver, if one exists.
- (void)cancelBackgroundImageRequestOperation
Declared In
UIButton+AFNetworking.h
cancelImageRequestOperation
Cancels any executing image operation for the receiver, if one exists.
- (void)cancelImageRequestOperation
Declared In
UIButton+AFNetworking.h
setBackgroundImageForState:withURL:
Asynchronously downloads an image from the specified URL, and sets it as the background image for the specified state once the request is finished. Any previous background image request for the receiver will be cancelled.
- (void)setBackgroundImageForState:(UIControlState)state withURL:(NSURL *)url
Parameters
- state
The control state.
- url
The URL used for the background image request.
Discussion
If the background image is cached locally, the background image is set immediately, otherwise the specified placeholder background image will be set immediately, and then the remote background image will be set once the request is finished.
Declared In
UIButton+AFNetworking.h
setBackgroundImageForState:withURL:placeholderImage:
Asynchronously downloads an image from the specified URL, and sets it as the background image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
- (void)setBackgroundImageForState:(UIControlState)state withURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage
Parameters
- state
The control state.
- url
The URL used for the background image request.
- placeholderImage
The background image to be set initially, until the background image request finishes. If
nil
, the button will not change its background image until the background 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.
Declared In
UIButton+AFNetworking.h
setBackgroundImageForState:withURLRequest:placeholderImage:success:failure:
Asynchronously downloads an image from the specified URL request, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
- (void)setBackgroundImageForState:(UIControlState)state withURLRequest:(NSURLRequest *)urlRequest placeholderImage:(UIImage *)placeholderImage success:(void ( ^ ) ( NSHTTPURLResponse *response , UIImage *image ))success failure:(void ( ^ ) ( NSError *error ))failure
Parameters
- state
The control state.
- urlRequest
The URL request used for the image request.
- placeholderImage
The background image to be set initially, until the background image request finishes. If
nil
, the button will not change its background image until the background 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.
If a success block is specified, it is the responsibility of the block to set the image of the button before returning. If no success block is specified, the default behavior of setting the image with setBackgroundImage:forState:
is applied.
Declared In
UIButton+AFNetworking.h
setImageForState:withURL:
Asynchronously downloads an image from the specified URL, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
- (void)setImageForState:(UIControlState)state withURL:(NSURL *)url
Parameters
- state
The control state.
- 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.
Declared In
UIButton+AFNetworking.h
setImageForState:withURL:placeholderImage:
Asynchronously downloads an image from the specified URL, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
- (void)setImageForState:(UIControlState)state withURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage
Parameters
- state
The control state.
- url
The URL used for the image request.
- placeholderImage
The image to be set initially, until the image request finishes. If
nil
, the button 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.
Declared In
UIButton+AFNetworking.h
setImageForState:withURLRequest:placeholderImage:success:failure:
Asynchronously downloads an image from the specified URL request, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
- (void)setImageForState:(UIControlState)state withURLRequest:(NSURLRequest *)urlRequest placeholderImage:(UIImage *)placeholderImage success:(void ( ^ ) ( NSHTTPURLResponse *response , UIImage *image ))success failure:(void ( ^ ) ( NSError *error ))failure
Parameters
- state
The control state.
- urlRequest
The URL request used for the image request.
- placeholderImage
The image to be set initially, until the image request finishes. If
nil
, the button 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 two arguments: the server response and the image. 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 a single argument: the 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 button before returning. If no success block is specified, the default behavior of setting the image with setImage:forState:
is applied.
Declared In
UIButton+AFNetworking.h