Merge pull request #560 from klaaspieter/imageURL-property
Keep a reference to the image URL
This commit is contained in:
commit
7abff886ae
|
@ -14,6 +14,14 @@
|
|||
*/
|
||||
@interface MKAnnotationView (WebCache)
|
||||
|
||||
/**
|
||||
* Get the current image URL.
|
||||
*
|
||||
* Note that because of the limitations of categories this property can get out of sync
|
||||
* if you use setImage: directly.
|
||||
*/
|
||||
- (NSURL *)imageURL;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
|
|
|
@ -9,11 +9,18 @@
|
|||
#import "MKAnnotationView+WebCache.h"
|
||||
#import "objc/runtime.h"
|
||||
|
||||
static char imageURLKey;
|
||||
static char operationKey;
|
||||
|
||||
@implementation MKAnnotationView (WebCache)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url {
|
||||
- (NSURL *)imageURL;
|
||||
{
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url
|
||||
{
|
||||
[self setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
|
@ -36,6 +43,7 @@ static char operationKey;
|
|||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
|
||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
self.image = placeholder;
|
||||
|
||||
if (url) {
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
*/
|
||||
@interface UIButton (WebCache)
|
||||
|
||||
/**
|
||||
* Get the current image URL.
|
||||
*/
|
||||
- (NSURL *)currentImageURL;
|
||||
|
||||
/**
|
||||
* Get the image URL for a control state.
|
||||
*
|
||||
* @param state Which state you want to know the URL for. The values are described in UIControlState.
|
||||
*/
|
||||
- (NSURL *)imageURLForState:(UIControlState)state;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
|
|
|
@ -9,11 +9,30 @@
|
|||
#import "UIButton+WebCache.h"
|
||||
#import "objc/runtime.h"
|
||||
|
||||
static char imageURLStorageKey;
|
||||
static char operationKey;
|
||||
|
||||
@implementation UIButton (WebCache)
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
||||
- (NSURL *)currentImageURL;
|
||||
{
|
||||
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||
|
||||
if (!url)
|
||||
{
|
||||
url = self.imageURLStorage[@(UIControlStateNormal)];
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
- (NSURL *)imageURLForState:(UIControlState)state;
|
||||
{
|
||||
return self.imageURLStorage[@(state)];
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state
|
||||
{
|
||||
[self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||
}
|
||||
|
||||
|
@ -36,6 +55,8 @@ static char operationKey;
|
|||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
|
||||
self.imageURLStorage[@(state)] = url;
|
||||
|
||||
[self setImage:placeholder forState:state];
|
||||
|
||||
if (url) {
|
||||
|
@ -111,4 +132,16 @@ static char operationKey;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *)imageURLStorage;
|
||||
{
|
||||
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||
if (!storage)
|
||||
{
|
||||
storage = [NSMutableDictionary dictionary];
|
||||
objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -44,6 +44,14 @@
|
|||
*/
|
||||
@interface UIImageView (WebCache)
|
||||
|
||||
/**
|
||||
* Get the current image URL.
|
||||
*
|
||||
* Note that because of the limitations of categories this property can get out of sync
|
||||
* if you use setImage: directly.
|
||||
*/
|
||||
- (NSURL *)imageURL;
|
||||
|
||||
/**
|
||||
* Set the imageView `image` with an `url`.
|
||||
*
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#import "UIImageView+WebCache.h"
|
||||
#import "objc/runtime.h"
|
||||
|
||||
static char imageURLKey;
|
||||
static char operationKey;
|
||||
static char operationArrayKey;
|
||||
|
||||
|
@ -40,6 +41,8 @@ static char operationArrayKey;
|
|||
|
||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||
[self cancelCurrentImageLoad];
|
||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
self.image = placeholder;
|
||||
|
||||
if (!(options & SDWebImageDelayPlaceholder)) {
|
||||
self.image = placeholder;
|
||||
|
@ -69,7 +72,13 @@ static char operationArrayKey;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
||||
- (NSURL *)imageURL;
|
||||
{
|
||||
return objc_getAssociatedObject(self, &imageURLKey);
|
||||
}
|
||||
|
||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs
|
||||
{
|
||||
[self cancelCurrentArrayLoad];
|
||||
__weak UIImageView *wself = self;
|
||||
|
||||
|
|
Loading…
Reference in New Issue