-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathUIImageView+SGImageCache.h
86 lines (73 loc) · 3.27 KB
/
UIImageView+SGImageCache.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// Created by matt on 22/05/14.
//
#if !TARGET_OS_WATCH
/**
* A `UIImageView` category with convenience setters for loading images from
* <SGImageCache>.
*/
#define SGImageViewImageChanged @"SGImageViewImageChanged"
@interface UIImageView (SGImageCache)
/**
* Fetches an image from <SGImageCache> and assigns it to the image view's
* `image`. If the image is not available in cache it will be fetched from
* the given URL asynchronously.
*/
- (void)setImageForURL:(NSString *)url;
/**
* Assigns a placeholder image to the image view's `image`, then fetches an
* image from <SGImageCache> to replace the placeholder. If the image is not
* available in cache it will be fetched from the given URL asynchronously.
*/
- (void)setImageForURL:(NSString *)url placeholder:(UIImage *)placeholder;
/**
* Assigns a placeholder image to the image view's `image`, then fetches an
* image from <SGImageCache> to replace the placeholder. If the image is not
* available in cache it will be fetched from the given URL asynchronously.
* The image will crossfade in from the placeholder with the given duration.
*/
- (void)setImageForURL:(NSString *)url
placeholder:(UIImage *)placeholder
crossFadeDuration:(NSTimeInterval)duration;
/**
* Assigns a placeholder image to the image view's `image`, then fetches an
* image from <SGImageCache> to replace the placeholder. If the image is not
* available in cache it will be fetched from the given URL asynchronously.
* Since image fetching is asynchornous, we might NOT want to set the imageview's
* image when the download completes. The `stillValid` block will be executed
* after the image request completes to check if the image should be set on the
* imageview. Return YES in the block to update the imageview's image.
*/
- (void)setImageForURL:(NSString*)url
placeholder:(UIImage*)placeholder
stillValid:(BOOL(^)(void))stillValid;
/**
* Assigns a placeholder image to the image view's `image`, then fetches an
* image from <SGImageCache> to replace the placeholder. If the image is not
* available in cache it will be fetched from the given URL asynchronously.
* The image will crossfade in from the placeholder with the given duration.
* Since image fetching is asynchornous, we might NOT want to set the imageview's
* image when the download completes. The `stillValid` block will be executed
* after the image request completes to check if the image should be set on the
* imageview. Return YES in the block to update the imageview's image.
*/
- (void)setImageForURL:(NSString *)url
placeholder:(UIImage *)placeholder
crossFadeDuration:(NSTimeInterval)duration
stillValid:(BOOL(^)(void))stillValid;
/**
* Fetches an image from <SGImageCache> and assigns it to the image view's
* `image`. If the image is not available in cache it will be fetched from
* the asset bundle with the given name.
*/
- (void)setImageWithName:(NSString *)name;
/**
* Assigns a placeholder image to the image view's `image`, then fetches an
* image from <SGImageCache> to replace the placeholder. If the image is not
* available in cache it will be fetched from the asset bundle with the given
* name.
*/
- (void)setImageWithName:(NSString *)name
crossFadeDuration:(NSTimeInterval)duration;
@end
#endif