Cocoa in the Shell

New class for NYXImagesKit : NYXProgressiveImageView

Jan 13, 2012

Some time ago, I showed how to progressively display an image while it was being downloaded using ImageIO.framework. Today I created a simple subclass of UIImageView in NYXImagesKit to take advantage of this feature.

As it’s a subclass of UIImageView, it’s really easy to use. Just do as you usually do, and call the loadImageAtURL: method when you want to download and display an image.

NYXProgressiveImageView* iv = [[NYXProgressiveImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 640.0f)];
[iv loadImageAtURL:[NSURL urlWithString:@"http://www.image.url"]];

There is also a protocol with two optional methods, the first will be called if the download was successful and will contain the downloaded image object. If you want to implement some sort of caching, it’s the place.

-(void)imageDownloadCompletedWithImage:(UIImage*)img;

The second will be called if the download failed, and will contain the downloaded data or nil.

-(void)imageDownloadFailedWithData:(NSData*)data;

The code for NYXImagesKit is available on my github page.

Tags: , ,