Skip to content

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.

License

Notifications You must be signed in to change notification settings

reden87/R87DownloaderImageView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

R87DownloaderImageView

Cocoapods Issues Platform Language License

Overview

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 example image

Installation

R87DownloaderImageView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "R87DownloaderImageView"

Usage

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.

Example

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];

Compatibility

iOS 5.0+

Contributing

Contributions are always welcome! (:

  1. Fork it ( http://github.com/reden87/R87DownloaderImageView/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The project is under the MIT License.

Todo

  • Create CocoaPod
  • make an internal image save solution where you can access an image with a custom ID you provided

About

Gergő Németh (reden87)

About

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published