A category on UIView that allows you to progressively download images. Leverages AFNetworking's image cache to make seamless image enhancements really easy.
It is common to download smaller images for use as thumbnails when rendering many records in a table view. When you visit the detail for a given page, you'd like to download a higher resolution image, but use the one we've already downloaded as a starting point, so the user doesn't get a flash of no content when the detail view controller loads.
This leverages AFNetworking's image cache, so all you need is a set of progressively enhanced URLs. It supports any number of requests, but you'll probably only use 2 (small/large).
- iOS 6.0
- AFNetworking
Install via CocoaPods. Here's a sample Podfile
:
platform :ios, '6.0'
pod 'AFNetworking'
pod 'AFProgressiveImageDownload'
Then run pod install
to integrate it with your Xcode project.
Import the header:
#import "UIImageView+AFProgressiveDownload.h"
Prepare a list of URLs:
NSArray *urls = @[ smallUrl, largeUrl ];
Load it on the image view:
[self.imageView setImageProgressivelyWithImageURLs:progressiveURLS
placeholderImage:self.placeholderImage
completion:^(NSURL *imageURL, BOOL success, NSError *error, BOOL completed) {
NSLog(@"Completed %@", imageURL);
// just to make the effect more obvious
sleep(1);
}];
Check out the provided sample project for a live demo. Here's what it looks like:
It's hard to see with scaled down images, but the one on the right is retina resolution.
AFProgressiveImageDownload is provided under the MIT license. See LICENSE for specifics.
This library is made possible by AFNetworking, which is doing all of the heavy lifting here. The demo project uses Creative Commons licensed images. Credits to Eugene Kukulka and WPZOOM.
Created as part of the Objective-C Hackathon on June 29th, 2013.