Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PauloMigAlmeida/8795546 to your computer and use it in GitHub Desktop.
Save PauloMigAlmeida/8795546 to your computer and use it in GitHub Desktop.
UIImageView Category to show an activity indicator when downloading images form internet using SDWebImage
//
// UIImageView+WebCacheWithActivityIndicator.h
//
// Created by Paulo Miguel Almeida on 2/3/14.
//
#import <UIKit/UIKit.h>
#import <SDWebImage/UIImageView+WebCache.h>
@interface UIImageView (WebCacheWithActivityIndicator)
- (void)setImageShowingActivityIndicatorWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
@end
//
// UIImageView+WebCacheWithActivityIndicator.m
//
// Created by Paulo Miguel Almeida on 2/3/14.
//
#import "UIImageView+WebCacheWithActivityIndicator.h"
@implementation UIImageView (WebCacheWithActivityIndicator)
- (void)setImageShowingActivityIndicatorWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock
{
UIActivityIndicatorView* activityIndication = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityIndication setFrame:CGRectMake((self.frame.size.width - activityIndication.frame.size.width) / 2 , (self.frame.size.height - activityIndication.frame.size.height) / 2 , activityIndication.frame.size.width , activityIndication.frame.size.width)];
[self addSubview:activityIndication];
[activityIndication startAnimating];
[self setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if(completedBlock)
{
completedBlock(image,error,cacheType);
}
[activityIndication stopAnimating];
[activityIndication removeFromSuperview];
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment