Created
February 4, 2014 00:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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