SDWebImage/UIImageView+WebCache.m

65 lines
1.3 KiB
Mathematica
Raw Normal View History

/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "UIImageView+WebCache.h"
#import "SDWebImageManager.h"
@implementation UIImageView (WebCache)
- (void)setImageWithURL:(NSURL *)url
{
[self setImageWithURL:url placeholderImage:nil];
}
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
{
SDWebImageManager *manager = [SDWebImageManager sharedManager];
// Remove in progress downloader from queue
[manager cancelForDelegate:self];
2010-06-12 22:37:47 +08:00
UIImage *cachedImage = nil;
if (url)
{
2010-06-12 22:37:47 +08:00
cachedImage = [manager imageWithURL:url];
}
else
{
self.image = placeholder;
}
if (cachedImage)
{
self.image = cachedImage;
}
else
{
if (placeholder)
{
self.image = placeholder;
}
2010-06-12 22:37:47 +08:00
if (url)
{
[manager downloadWithURL:url delegate:self];
}
}
}
2010-06-11 22:32:35 +08:00
- (void)cancelCurrentImageLoad
{
[[SDWebImageManager sharedManager] cancelForDelegate:self];
}
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
{
self.image = image;
}
@end