I\'m using SDWebView image and i want to show an Activity Indicator as placeholder, while fetching the image from remote.
I tried Malek\'s answer here How to show an act
Based on Can Ürek's answer you might wanna create a category to make it easier to use across multiple applications and without modify SDWebImage framework.
Header file:
#import
#import
@interface UIImageView (WebCacheWithActivityIndicator)
- (void)setImageShowingActivityIndicatorWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;
@end
Implementation file:
#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
Hope it helps you out guys
Cheers