60 lines
1.2 KiB
Objective-C
60 lines
1.2 KiB
Objective-C
/*
|
|
* 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];
|
|
|
|
if (!url)
|
|
{
|
|
self.image = nil;
|
|
return;
|
|
}
|
|
|
|
UIImage *cachedImage = [manager imageWithURL:url];
|
|
|
|
if (cachedImage)
|
|
{
|
|
self.image = cachedImage;
|
|
}
|
|
else
|
|
{
|
|
if (placeholder)
|
|
{
|
|
self.image = placeholder;
|
|
}
|
|
|
|
[manager downloadWithURL:url delegate:self];
|
|
}
|
|
}
|
|
|
|
- (void)cancelCurrentImageLoad
|
|
{
|
|
[[SDWebImageManager sharedManager] cancelForDelegate:self];
|
|
}
|
|
|
|
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
|
|
{
|
|
self.image = image;
|
|
}
|
|
|
|
@end
|