|
@@ -18,8 +18,14 @@ static char imageURLStorageKey; |
|
@@ -18,8 +18,14 @@ static char imageURLStorageKey; |
18
|
|
18
|
|
19
|
typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary;
|
19
|
typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary;
|
20
|
|
20
|
|
|
|
21
|
+static inline NSNumber * backgroundImageURLKeyForState(UIControlState state) {
|
|
|
22
|
+ return @(NSUIntegerMax - state - 1);
|
|
|
23
|
+}
|
|
|
24
|
+
|
21
|
@implementation UIButton (WebCache)
|
25
|
@implementation UIButton (WebCache)
|
22
|
|
26
|
|
|
|
27
|
+#pragma mark - Image
|
|
|
28
|
+
|
23
|
- (nullable NSURL *)sd_currentImageURL {
|
29
|
- (nullable NSURL *)sd_currentImageURL {
|
24
|
NSURL *url = self.imageURLStorage[@(self.state)];
|
30
|
NSURL *url = self.imageURLStorage[@(self.state)];
|
25
|
|
31
|
|
|
@@ -34,8 +40,6 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
|
@@ -34,8 +40,6 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
34
|
return self.imageURLStorage[@(state)];
|
40
|
return self.imageURLStorage[@(state)];
|
35
|
}
|
41
|
}
|
36
|
|
42
|
|
37
|
-#pragma mark - Image
|
|
|
38
|
-
|
|
|
39
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
43
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
40
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
44
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
41
|
}
|
45
|
}
|
|
@@ -82,6 +86,20 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
|
@@ -82,6 +86,20 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
82
|
|
86
|
|
83
|
#pragma mark - Background image
|
87
|
#pragma mark - Background image
|
84
|
|
88
|
|
|
|
89
|
+- (nullable NSURL *)sd_currentBackgroundImageURL {
|
|
|
90
|
+ NSURL *url = self.imageURLStorage[backgroundImageURLKeyForState(self.state)];
|
|
|
91
|
+
|
|
|
92
|
+ if (!url) {
|
|
|
93
|
+ url = self.imageURLStorage[backgroundImageURLKeyForState(UIControlStateNormal)];
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ return url;
|
|
|
97
|
+}
|
|
|
98
|
+
|
|
|
99
|
+- (nullable NSURL *)sd_backgroundImageURLForState:(UIControlState)state {
|
|
|
100
|
+ return self.imageURLStorage[backgroundImageURLKeyForState(state)];
|
|
|
101
|
+}
|
|
|
102
|
+
|
85
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
103
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
86
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
104
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
87
|
}
|
105
|
}
|
|
@@ -108,11 +126,11 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
|
@@ -108,11 +126,11 @@ typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary; |
108
|
options:(SDWebImageOptions)options
|
126
|
options:(SDWebImageOptions)options
|
109
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
127
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
110
|
if (!url) {
|
128
|
if (!url) {
|
111
|
- [self.imageURLStorage removeObjectForKey:@(state)];
|
129
|
+ [self.imageURLStorage removeObjectForKey:backgroundImageURLKeyForState(state)];
|
112
|
return;
|
130
|
return;
|
113
|
}
|
131
|
}
|
114
|
|
132
|
|
115
|
- self.imageURLStorage[@(state)] = url;
|
133
|
+ self.imageURLStorage[backgroundImageURLKeyForState(state)] = url;
|
116
|
|
134
|
|
117
|
__weak typeof(self)weakSelf = self;
|
135
|
__weak typeof(self)weakSelf = self;
|
118
|
[self sd_internalSetImageWithURL:url
|
136
|
[self sd_internalSetImageWithURL:url
|