Permalink
Browse files

Added AsyncImageView 1.0

  • Loading branch information...
0 parents commit 05bbe742fa090054427447317806eabac9f1dcdb @nicklockwood committed Jul 24, 2011
Showing with 167 additions and 0 deletions.
  1. +38 −0 AsyncImageView.h
  2. +74 −0 AsyncImageView.m
  3. +22 −0 LICENCE.md
  4. +30 −0 README.md
  5. +3 −0 RELEASE NOTES.md
@@ -0,0 +1,38 @@
+//
+// AsyncImageView.h
+//
+// Created by Nick Lockwood on 03/04/2011.
+// Copyright 2010 Charcoal Design. All rights reserved.
+//
+// Get the latest version of AsyncImageView from either of these locations:
+//
+// http://charcoaldesign.co.uk/source/cocoa#asyncimageview
+// https://github.com/demosthenese/AsyncImageView
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it
+// freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+
+#import <UIKit/UIKit.h>
+
+
+@interface AsyncImageView : UIImageView
+
+@property (nonatomic, retain) NSURL *imageURL;
+
+@end
@@ -0,0 +1,74 @@
+//
+// AsyncImageView.m
+//
+// Created by Nick Lockwood on 03/04/2011.
+// Copyright 2011 Charcoal Design. All rights reserved.
+//
+// Get the latest version of AsyncImageView from either of these locations:
+//
+// http://charcoaldesign.co.uk/source/cocoa#asyncimageview
+// https://github.com/demosthenese/AsyncImageView
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it
+// freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+
+#import "AsyncImageView.h"
+
+
+@implementation AsyncImageView
+
+@synthesize imageURL;
+
+- (void)downloadImageURLInBackground:(NSURL *)_imageURL
+{
+ AsyncImageView *selfReference = [self retain];
+ @synchronized ([self class])
+ {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSData *data = [[NSData alloc] initWithContentsOfURL:_imageURL];
+ UIImage *image = [[UIImage alloc] initWithData:data];
+ if ([_imageURL isEqual:imageURL])
+ {
+ [self performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
+ }
+ [image release];
+ [data release];
+ [pool release];
+ }
+ [selfReference release];
+}
+
+- (void)setImageURL:(NSURL *)_imageURL
+{
+ if (imageURL != _imageURL)
+ {
+ [imageURL release];
+ imageURL = [_imageURL retain];
+ [self performSelectorInBackground:@selector(downloadImageURLInBackground:)
+ withObject:imageURL];
+ }
+}
+
+- (void)dealloc
+{
+ [imageURL release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,22 @@
+AsyncImageView
+version 1.0, April 3rd, 2011
+
+Copyright (C) 2011 Charcoal Design
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source distribution.
@@ -0,0 +1,30 @@
+Purpose
+--------------
+
+AsyncImageView is a simple class for loading and displaying images asynchronously on iOS so that they do not lock up the UI. AsyncImageView works with URLs so it can be used with either local or remote files. Note however that AsyncImageView does not currently implement any form of caching or de-duplication of images, so it is up to the application to ensure that multiple instances of the same image are not loaded unnecessarily.
+
+
+Installation
+--------------
+
+To use the AsyncImageView in an app, just drag the class files into your project.
+
+
+Properties
+------------
+
+Besides the standard UIImageView properties that it inherits, AsyncImageView has only one new property:
+
+ @property (nonatomic, retain) NSURL *imageURL;
+
+Upon setting this property, AsyncImageView will begin loading/downloading the specified image on a background thread. Once the image file has loaded, the AsyncImageView image property will be set to the resultant image.
+
+
+Usage
+--------
+
+To load or download an image, simply point the imageURL property at the desired image.
+
+If you want to display a placeholder image in the meantime, just manually set the image property to your placeholder image and it will be overwritten once the image specified by the URL has loaded.
+
+To detect when the image has finished loading, you can use KVO (Key Value Coding) to set up an observer on the image property. When the image has finished loading, the image will be set, and with KVO you can detect this and react accordingly.
@@ -0,0 +1,3 @@
+Version 1.0
+
+- Initial release

0 comments on commit 05bbe74

Please sign in to comment.