Currently i am integrating SDWebImage in my project by following below things
1)#import "UIButton+WebCache.h"
2)[button setImageWithURL:url placeholderImage:[UIImage imageNamed:@"no_photo.png"]];
So it will show the list of image present in URL above the respective buttons.
But Now i want to show an activity indicator above button when the image is getting downloaded ,So how can i do this?
the best way is to add the activityIndicator in all "setImage" functions in UIImageView+WebCache.m, after that you remove it in "webImageManager:r didFinishWithImage:" , i test it in device and it work smoothly, her's an example :
and you remove it with a fade animation ;) :
Works like a charm for me :
Swift 3:
Swift 4: (Edit : Updates)
The best way I have found to do this is to use the SDWebImageManager class. Your view controller or some other class will then need to conform to the SDWebImageManagerDelegate protocol.
Once the image has been downloaded the delegate method will be called:
There is also a delegate method for when an error occurs downloading an image
If you have more than one button you may have problems determining which image belongs to which button after the image has downloaded. In this case you may need to have a button subclass which handles the download as above and then updates its own image.
Hope that helps.
Last solution
You can download UIActivityIndicator-for-SDWebImage, which is easiest way to add a UIActivityView to your SDWebImage view. Using CocoaPods, just add this line to your podfile:
You can use one of these lines depending on your preferences:
Example of Use
Just import
and use this code