Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <AFNetworking+ImageActivityIndicator/UIImageView+AFNetworking_UIActivityIndicatorView.h>
#import <AFNetworking_ImageActivityIndicator/UIImageView+AFNetworking_UIActivityIndicatorView.h>
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,29 @@
* By default, URL requests have an `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, yet still show an activity indicator, use `setImageWithURLRequest:usingActivityIndicatorStyle:success:failure:`
*
* @param url The URL used for the image request.
* @param style The style for the activity indicator
* @param style The style for the activity indicator.
*/
- (void)setImageWithURL:(NSURL *)url usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style;

/**
* 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. Use

* If the image is cached locally, the image is set immediately, otherwise the placeholder is shown and an activity indicator view will be added as a subview of the image view, centered, start animating, and then the remote image will be set once the request is finished.

* By default, URL requests have an `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, yet still show an activity indicator, use `setImageWithURLRequest:usingActivityIndicatorStyle:success:failure:`
*
* @param url The URL used for the image request.
* @param style The style for the activity indicator.
* @param color The color of activity indicator.
* @param 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.
* @param failureImage The image to set if image request operation finishes unsuccessfully.
*/
- (void)setImageWithURL:(NSURL *)url
activityIndicatorStyle:(UIActivityIndicatorViewStyle)style
activityIndicatorColor:(UIColor *)color
placeholderImage:(UIImage *)placeholderImage
failureImage:(UIImage *)failureImage;

/**
* 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.

Expand All @@ -73,14 +92,18 @@
* 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.
*
* @param urlRequest The URL request used for the image request.
* @param style The style for the activity indicator.
* @param color The color of activity indicator.
* @param 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.
* @param style The style for the activity indicator
* @param failureImage The image to set if image request operation finishes unsuccessfully.
* @param 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`.
* @param 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.
*/
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
placeholderImage:(UIImage *)placeholderImage
usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
activityIndicatorColor:(UIColor *)color
placeholderImage:(UIImage *)placeholderImage
failureImage:(UIImage *)failureImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,43 @@ - (void)removeActivityIndicatorView
- (void)setImageWithURL:(NSURL *)url usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
{
[self setImageWithURLRequest:[NSURLRequest requestWithURL:url]
placeholderImage:nil
usingActivityIndicatorStyle:style
activityIndicatorColor:nil
placeholderImage:nil
failureImage:nil
success:nil
failure:nil];
}

- (void)setImageWithURL:(NSURL *)url
activityIndicatorStyle:(UIActivityIndicatorViewStyle)style
activityIndicatorColor:(UIColor *)color
placeholderImage:(UIImage *)placeholderImage
failureImage:(UIImage *)failureImage;
{
[self setImageWithURLRequest:[NSURLRequest requestWithURL:url]
usingActivityIndicatorStyle:style
activityIndicatorColor:color
placeholderImage:placeholderImage
failureImage:failureImage
success:nil
failure:nil];
}

- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
placeholderImage:(UIImage *)placeholderImage
usingActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
activityIndicatorColor:(UIColor *)color
placeholderImage:(UIImage *)placeholderImage
failureImage:(UIImage *)failureImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
if (urlRequest.URL == nil) {
self.image = nil;
self.image = failureImage;
return;
}

[self af_addActivityIndicatorWithStyle:style];
[self af_addActivityIndicatorWithStyle:style color:color];

__weak UIImageView *weakSelf = self;

Expand All @@ -108,19 +127,22 @@ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest

if (failure) {
failure(request, response, error);
} else {
strongSelf = failureImage;
}
}];
}

#pragma mark - Private Helpers

- (void)af_addActivityIndicatorWithStyle:(UIActivityIndicatorViewStyle)style
color:(UIColor *)color
{
UIActivityIndicatorView *activityIndicator = [self activityIndicatorView];

if (!activityIndicator) {

activityIndicator = [self af_createActivityIndicatorWithStyle:style];
activityIndicator = [self af_createActivityIndicatorWithStyle:style color:color];
[self setActivityIndicatorView:activityIndicator];

if ([NSThread isMainThread]) {
Expand All @@ -147,13 +169,18 @@ - (void)af_addActivityIndicatorWithStyle:(UIActivityIndicatorViewStyle)style
}

- (UIActivityIndicatorView *)af_createActivityIndicatorWithStyle:(UIActivityIndicatorViewStyle)style
color:(UIColor *)color
{
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
activityIndicator.userInteractionEnabled = NO;
activityIndicator.center = self.center;
activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;


if (color) {
activityIndicator.color = color;
}

return activityIndicator;
}

Expand Down