forked from mzarra/MSZ_Shared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIImageView+ZSAssetManagerAdditions.m
49 lines (38 loc) · 1.23 KB
/
UIImageView+ZSAssetManagerAdditions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// UIImage+ZSAssetManagerAdditions.m
// iPad12
//
// Created by Patrick Hughes on 8/8/12.
// Copyright (c) 2012 Empirical Development LLC. All rights reserved.
//
#import "UIImageView+ZSAssetManagerAdditions.h"
#import "ZSAssetManager.h"
#import <objc/runtime.h>
static char const * const assetManagerImageURLKey = "assetManagerImageURLKey";
@implementation UIImageView (ZSAssetManagerAdditions)
- (void)setImageWithURL:(NSURL *)url
{
objc_setAssociatedObject(self, assetManagerImageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.image = nil;
if (!url) {
DLog(@"nil url passed");
return;
}
__weak UIImageView *blockSelf = self;
[[ZSAssetManager sharedAssetManager] fetchImageForURL:url withCompletionBlock:^(NSURL *fetchedUrl, UIImage *image) {
NSURL *currentURL = (NSURL*) objc_getAssociatedObject(self, assetManagerImageURLKey);
if ([currentURL isEqual:fetchedUrl]) {
blockSelf.image = image;
}
}];
}
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage
{
// Request the image from the asset manager.
[self setImageWithURL:url];
// If the asset manager has it, don't set the placeholder.
if (!self.image) {
self.image = placeholderImage;
}
}
@end