diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 4549aeb1..2bb19bc9 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -68,7 +68,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which * could take a while). */ - SDWebImageHighPriority = 1 << 8 + SDWebImageHighPriority = 1 << 8, + + /** + * By default, placeholder images are loaded while the image is loading. This flag will delay the loading + * of the placeholder image until after the image has finished loading. + */ + SDWebImageDelayPlaceholder = 1 << 9 }; typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType); diff --git a/SDWebImage/UIImageView+WebCache.h b/SDWebImage/UIImageView+WebCache.h index 46f1f0b0..cfdd6757 100644 --- a/SDWebImage/UIImageView+WebCache.h +++ b/SDWebImage/UIImageView+WebCache.h @@ -120,7 +120,7 @@ /** * Set the imageView `image` with an `url`, placeholder and custom options. * - * The downloand is asynchronous and cached. + * The download is asynchronous and cached. * * @param url The url for the image. * @param placeholder The image to be set initially, until the image request finishes. diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index ed65a0ed..e0de97d0 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -40,9 +40,11 @@ static char operationArrayKey; - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { [self cancelCurrentImageLoad]; - - self.image = placeholder; - + + if (!(options & SDWebImageDelayPlaceholder)) { + self.image = placeholder; + } + if (url) { __weak UIImageView *wself = self; id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { @@ -52,6 +54,11 @@ static char operationArrayKey; if (image) { wself.image = image; [wself setNeedsLayout]; + } else { + if ((options & SDWebImageDelayPlaceholder)) { + wself.image = placeholder; + [wself setNeedsLayout]; + } } if (completedBlock && finished) { completedBlock(image, error, cacheType);