R87DownloaderImageView
is a UIImageView
subclass which makes possible to download an image from the provided link.
While the download is in progress the default or a custom propgress bar is displayed, the download returns a success block with the downloaded image or a failure block in case of an error.
R87DownloaderImageView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "R87DownloaderImageView"
Use this method to start image download from a server:
- (void)downloadImageWithLink:(NSString *)imageLink
withSuccessBlock:(void(^)(NSData *imageData))successBlock
failureBlock:(void(^)(NSError *error))failureBlock;
Optionally you can set the image
property before the downloadImageWithLink:withSuccessBlock:failureBlock
method. In this case the method returns in the success block with nil parameter.
You can set the activityIndicator
property before the downloadImageWithLink:withSuccessBlock:failureBlock
method. In this case the the provided view vill be displayed while the download is in progress.
You can set the errorImage
property before the downloadImageWithLink:withSuccessBlock:failureBlock
method. This image will be displayed if an error occures.
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// set image if exists
NSData *imageData = [userDefaults objectForKey:@"image"];
self.imageView.image = [UIImage imageWithData:imageData];
// set custom loading indicator
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityIndicator startAnimating];
self.imageView.activityIndicator = activityIndicator;
// set error image
self.imageView.errorImage = [UIImage imageNamed:@"errorImage"];
// download image (does nothing if the image exists)
[self.imageView downloadImageWithLink:@"http://lorempixel.com/400/400/" withSuccessBlock:^(NSData *imageData) {
[userDefaults setObject:imageData forKey:@"image"];
[userDefaults synchronize];
} failureBlock:nil];
iOS 5.0+
Contributions are always welcome! (:
- Fork it ( http://github.com/reden87/R87DownloaderImageView/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The project is under the MIT License.
Create CocoaPod✓- make an internal image save solution where you can access an image with a custom ID you provided
Gergő Németh (reden87)