Latest2.0.0
Homepagehttps://github.com/reden87/R87DownloaderImageView
LicenseMIT
Platformsios 6.0, tvos 9.0, requires ARC
FrameworksFoundation, UIKit
Authors

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)

Latest podspec

{
    "name": "R87DownloaderImageView",
    "version": "2.0.0",
    "summary": "R87DownloaderImageView is a UIImageView subclass which makes possible to download an image from the provided link.",
    "description": "R87DownloaderImageView is a UIImageView subclass which makes possible to download an image from the provided link.nnWhile 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.",
    "homepage": "https://github.com/reden87/R87DownloaderImageView",
    "screenshots": "https://camo.githubusercontent.com/e2286c9a0e78c6bfdc2534e4f56027c8041e3a1a/687474703a2f2f726564656e38372e696e666f2f4769744875622f523837496d616765566965772e676966",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Gergu0151 Nu00e9meth": "http://reden87.info/"
    },
    "social_media_url": "http://twitter.com/reden87",
    "platforms": {
        "ios": "6.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/reden87/R87DownloaderImageView.git",
        "tag": "2.0.0"
    },
    "source_files": "R87DownloaderImageView/*.{h,m}",
    "requires_arc": true,
    "frameworks": [
        "Foundation",
        "UIKit"
    ]
}

Pin It on Pinterest

Share This