TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Jan 2016 |
Maintained by Antoni Kedracki, Polidea.
Image manager/downloader for iOS
PLXURLImageProvider * provider = [PLXURLImageProvider new];
PLXImageManager * manager = [[PLXImageManager alloc] initWithProvider:provider];
The provider is responsible for retrieving a image if it is not available in cache. The standard PLXURLImageProvider is provided as convenience. It takes a URL and simply downloads up to 5 images at once. By implementing the PLXImageManagerProvider protocol yourself, you can adapt the manager to fit your needs.
[manager imageForIdentifier:@”http://placehold.it/350/00aa00/ffffff”
placeholder:[UIImage imageNamed:@”placeholder”
callback:^(UIImage *image, BOOL isPlaceholder) {
//consume the image here
}];
The -imageForIdentifier:placeholder:callback: method returns a PLXImageManagerRequestToken that can be used to cancel requests for images.
This is important in scenarios like scrolling a UITableView, when cells can disappear before the download finishes. Canceling those will spare network usage, and reduce the time for the right image to appear.
PLXImageManagerRequestToken * token = nil;
//get token
token = [manager imageForIdentifier:@”http://placehold.it/350/00aa00/ffffff”
placeholder:[UIImage imageNamed:@”placeholder”
callback:^(UIImage *image, BOOL isPlaceholder) {
//consume the image here
}];
//cancel the download
[token cancel];
A convenience method is provided to store (and retrieve) a token on any NSObject subclass.
//storing a token
[aObject plx_storeToken:token];
//retrieving a token
token = [aObject plx_retrieveToken];
PLXImageManager makes use of a combination of memory and file based caches. Refer to the documentation for the memoryCacheCountLimit and fileCacheTotalSizeLimit properties for details.
The included example project demonstrates:
To run it, clone the repo, and run pod install
from the Example directory first.
iOS 7+
PLXImageManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "PLXImageManager"
Antoni Kedracki, [email protected]
You can read more about the internal workings of PLImageManager here.
PLXImageManager is available under the BSD license. See the LICENSE file for more info.
Copyright (c) 2013 Polidea. This software is licensed under the BSD License.