UIImageView+HighlightedWebCache.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "UIImageView+HighlightedWebCache.h"
  9. #if SD_UIKIT
  10. #import "UIView+WebCacheOperation.h"
  11. #import "UIView+WebCache.h"
  12. #import "SDInternalMacros.h"
  13. static NSString * const SDHighlightedImageOperationKey = @"UIImageViewImageOperationHighlighted";
  14. @implementation UIImageView (HighlightedWebCache)
  15. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url {
  16. [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
  17. }
  18. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url options:(SDWebImageOptions)options {
  19. [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
  20. }
  21. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url options:(SDWebImageOptions)options context:(nullable SDWebImageContext *)context {
  22. [self sd_setHighlightedImageWithURL:url options:options context:context progress:nil completed:nil];
  23. }
  24. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
  25. [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
  26. }
  27. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock {
  28. [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
  29. }
  30. - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(nullable SDImageLoaderProgressBlock)progressBlock completed:(nullable SDExternalCompletionBlock)completedBlock {
  31. [self sd_setHighlightedImageWithURL:url options:options context:nil progress:progressBlock completed:completedBlock];
  32. }
  33. - (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
  34. options:(SDWebImageOptions)options
  35. context:(nullable SDWebImageContext *)context
  36. progress:(nullable SDImageLoaderProgressBlock)progressBlock
  37. completed:(nullable SDExternalCompletionBlock)completedBlock {
  38. @weakify(self);
  39. SDWebImageMutableContext *mutableContext;
  40. if (context) {
  41. mutableContext = [context mutableCopy];
  42. } else {
  43. mutableContext = [NSMutableDictionary dictionary];
  44. }
  45. mutableContext[SDWebImageContextSetImageOperationKey] = SDHighlightedImageOperationKey;
  46. [self sd_internalSetImageWithURL:url
  47. placeholderImage:nil
  48. options:options
  49. context:mutableContext
  50. setImageBlock:^(UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  51. @strongify(self);
  52. self.highlightedImage = image;
  53. }
  54. progress:progressBlock
  55. completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
  56. if (completedBlock) {
  57. completedBlock(image, error, cacheType, imageURL);
  58. }
  59. }];
  60. }
  61. @end
  62. #endif