Async UIImageView w/Cache & Progress

Async UIImageView w/Cache & Progress

Replacement for UIImageView that adds asynchronous load capability, caching, activity indicator, load progress bar & default image.

LTAsyncImageView is a powerful replacement for UIImageView.

What it adds:

  • The ability to load an image from the web, asynchronously (so multiple load can be started the same time while doing anything else)
  • A settable internally managed cache feature, no need of external library to install, that will prevent your servers from being charged by too much requests of the same images from the same client
  • A settable default image to be shown while the distant image is loading
  • An optional UIActivityIndicator, self adjusting in size (it chooses between small or large size depending of the size of the component)
  • An option UIProgressBar, showing the downloading progression

We use it in several applications, inside tableViews for example, to load images illustrating lists.



To install the component into your project, simply Drag'n Drop both LTAsyncImageView.h & LTAsyncImageView.m into your project :

alt text


How to use

First, ensure that LTAsyncImageView.h is included into the header file of your view controller, or into the yourproject-prefix.pch if you want it to be accessible from any view / viewController :

#import "LTAsyncImageView.h"

If you want to transform an UIImageView from your xib file into LTAsyncImageView, simply change its type from UIImageView to LTAsyncImageView (as it is a descendant of UIImaveView) :

alt text

Then, don't forget to link your image from the nib editor into the header definitions :

LTAsyncImageView *myImage;

How to set the default image ?

If you use LTAsyncImageView as a component from the nib editor, then the image you'll set on it will automatically be considered as the default image.

Otherwise, you can manually set it :

[myImage setDefaultImage:[UIImage imageNamed:@"MyDefaultImage.png"]];
// where MyDefaultImage.png is the name of the image you want to be set as default.

How to start loading a distant image ?

If you want the component to load a distant image, you can use the following method:

[myImage  startPreloadingDistantPictureWithUrl:@""];

This will load the distant image, and show the activity indicator and the progress-bar if it has been set to YES (default values).

How to use the image cache ?

LTAsyncImageView comes with an internal cache system that will prevent your servers from being charged by to many request of the same resource by the same user (for example if your imageview is inside an UITableView and the user scrolls up/down).

The default duration time of cache retention is set to 24 hours.

It can be changed by using the following methods :

- (void)setCacheDurationForDays:(int)nbDays;
// set the cache duration in days

- (void)setCacheDurationForHours:(int)nbHours;
// set the cache duration in hours

- (void)setCacheDurationForMinutes:(int)nbMinutes;
// set the cache duration in minutes

To ask LTAsyncImageView to load an external image using the cache system, invoque this method :

[myImage startPreloadingAndCacheDistantPictureWithUrl:@""];

When calling this method, the system will search if the image has not been previously loaded and if its "age" feet into the cache duration value. If so, then it is directly presented into LTAsyncImageView. If not, it will load it externally (showing activity indicator & progress if needed), then save it for a future reuse.

How to show/hide the activity controller ?

When LTAsyncImageView is loading an image from the internet, you can decide to show an UIActivityIndicator in front of the default image to let the user understand something is loading :

[myImage showActivityIndicator:YES];

If you want to hide it, simply set its value to NO.

How to show/hide the progress indicator ?

When LTAsyncImageView is loading an image from the internet, you can decide to show an ProgressBar in front of the default image to let the user understand something is loading, and to show him when the image will be available to show :

[myImage showProgress:YES];

If you want to hide it, simply set its value to NO.

How to change the way LTAsyncImageView respects the aspect-ratio ?

By default, the component respects the aspect-ratio, that means that if the loaded image aspect-ratio is not the same as the LTAsyncImageView width & height ratio, then if will not fill it entirely.

If you want to bypass this, and ensure the image will fill entirely the view, even if the resulted image is deformed, call this method:

[myImage setKeepAspectRatio:NO];


As a bonus, LTAsyncImageView can shake itself the same way our component LTShakeAndDeleteView does.

To invoque the "shaking" of LTAsyncImageView, use :

[myImage startShaking];

And to stop it, simply use :

[myImage stopShaking];


- (void)setDefaultImage:(UIImage *)image;

Sets the default image. The default image is an image shown when no other image has been loaded by the component.

- (void)startPreloadingDistantPictureWithUrl:(NSString *)url;

Ask the component to load a distant image, from a web server (it can be a jpeg or a png file). When calling it, the default image is shown, the ActivityIndicator and the ProgressBar too (if they've not been disabled), the distant file is loaded, then everything fade in/out for the final image to be shown.

- (void)startPreloadingAndCacheDistantPictureWithUrl:(NSString *)url;

Same main functionality as for startPreloadingDistantPictureWithUrl, it adds a cache feature, that prevent from loading again and again through the webserver if it has already been loaded.

- (void)setCacheDurationForDays:(int)nbDays;

Sets the cache duration (the duration telling not to reload an image again) in nbDays days.

- (void)setCacheDurationForHours:(int)nbHours;

Sets the cache duration (the duration telling not to reload an image again) in nbHours hours.

- (void)setCacheDurationForMinutes:(int)nbMinutes;

Sets the cache duration (the duration telling not to reload an image again) in nbMinutes minutes.

 - (void)startShaking;

Start shaking the view, using the same effect as for our other component Shake And Delete View for iOS

 - (void)stopShaking;

Stop shaking the view.

 - (void)setKeepAspectRatio:(BOOL)yesno;

If set to YES, then the aspect ratio will be kept to prevent image deformation.

 - (void)showProgress:(BOOL)yesno;

If set to YES, then a download progressBar will be shown to see how much size has currently been loaded.

 - (void)showActivityIndicator:(BOOL)yesno;

If set to Yes, then an activityIndicator will be shown while loading from the net.



- (void)LTAsyncImageReceived:(UIImage *)image forView:(id)view;

Called when a distant image has successfully been loaded. It returns the loaded image and a pointer to the LTAsyncImageView affected.

- (void)LTAsyncImageError:(NSString *)error;

Called when a network error occured when trying to load a distant image.

You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.


Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.

2 licenses, starting from From » $25.99 14 day money-back guarantee View Licenses
or Get a quote

for customization or integration services

  • Good product work as expected. Fast answer from the technical support.
    DL Daniel Lusignan
    2 years ago, 0 comments
    Was this helpful?
Post a comment

Or enter your name and Email
  • Laurent Taupin Developer 2 years ago
    Hello Josh... Well it is not its "job" because first, it is an UIImageView so it can show only one Image, second the only possibility to do so is to have an API on the server side that is able to provide to your application the list of a dir (which cannot be available from outside your server, for security reason ;-) )... Hope this will help. Bests.
  • JS josh sroka 2 years ago
    Can this load an entire folder of images from a web server?