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 activity indicator in SDWebImage, but it seems that
UIImage *cachedImage = [manager imageWithURL:url];
is deprecated.
Is there anyone using this library that could tell me how can i insert an Activity Indicator while loading the image?
EDIT
Following the indications of Michael Frederick, i ended up with this code and everything's working fine.
UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
activityIndicator.center = CGPointMake(self.tipImage.frame.size.width /2, self.tipImage.frame.size.height/2);
[imageView setImageWithURL:[NSURL URLWithString:imageString]
placeholderImage:nil options:SDWebImageProgressiveDownload
success:^(UIImage *image) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }
failure:^(NSError *error) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }];
[imageView addSubview:activityIndicator];
This is how you do it:
That's my solution. In that file : UIImageView+WebCache.m
Find that method and change like that:
Solution updated for Swift 2.0 for using SDWebImage to load image URL
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:
Implementation file:
Hope it helps you out guys
Cheers
The above code is slightly wrong. The line 'activityIndicator.center = imageView.center' does not give you the correct coordinates to center the progress view. For me, it was showing the indicator below the cell.
Note - I am using the latest version of the SDWebImage code so the method is slightly different. I am also using a UIButton for the imageView
Try this: