- Drop-in image view replacement that loads from remote URLs asynchronously
- Support for image views created in interface builder
- Support for MIME type validation
- Optional delegate protocol for relaying image, errors, etc
- Shows activity indicatior during download
- Fully supports caching via NSURLConnection
- Well-documented code makes for easy extension
- Free!
The code is well-documented so you should be able to tell what's going on rather quickly. Here's how to implement the control:
- Add the files under the component's
source
directory to your project. - Import the components header into your header or implementation.
- Create an instance of JBAsyncImageView using the initializer.
- That's it!
NSURL *urlToLoad = [NSURL URLWithString:@"http://f.cl.ly/items/3T0V0w0G3D0Q411k1p1n/congrats.png"];
JBAsyncImageView *asyncImageView = [[JBAsyncImageView alloc] initWithURL:urlToLoad];
[self.view addSubview:asyncImageView];
For those using interface builder, the technique is a bit simpler:
- Create the image view in IB.
- Set the class to JBAsyncImageView
- In your view controller:
asyncImageView.imageURL = [NSURL URLWithString:@"http://f.cl.ly/items/3T0V0w0G3D0Q411k1p1n/congrats.png"];
The JBAsyncImageViewDelegate
protocol should be implemented to handle errors generated from the control. The following protocol definitions are available:
Called prior to beginning download of the image (optional)
-(void)imageView:(JBAsyncImageView *)sender willLoadImageFromURL:(NSURL *)urlToLoad;
Called when the download fails for various reasons (optional)
-(void)imageView:(JBAsyncImageView *)sender failedLoadingImageFromURL:(NSURL *)url withError:(NSError *)error;
Called once the download completes successfully (optional)
-(void)imageView:(JBAsyncImageView *)sender loadedImage:(UIImage *)imageLoaded fromURL:(NSURL *)url;
A working example is provided in the project's source.
MIT/X11 Open Source License
- Fork it!
- Make your changes in a new branch
- Submit a pull request