SVGKImageView+WebCache.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // SVGKImageView+WebCache.h
  3. // SDWebImageSVGPlugin
  4. //
  5. // Created by DreamPiggy on 2018/10/10.
  6. //
  7. #if __has_include(<SVGKit/SVGKit.h>)
  8. #import <SVGKit/SVGKit.h>
  9. #else
  10. @import SVGKit;
  11. #endif
  12. #import "SDWebImageSVGKitDefine.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. @interface SVGKImageView (WebCache)
  15. /**
  16. * Unlike `UIView`, `SVGKImageView`'s subclass does not follows `UIView.contentMode` property, the position of SVG vector image is controled by `SVGKImage` instance with SVG's viewport && viewbox information. You can adjust it after image was loading, however it's not so convenient.
  17. * So we provide a simple solution. If you want the same behavior like UIImageView to use `contentMode` property to position SVG images, set this value to YES and we'll resize the SVG image to correspond `contentMode` of `SVGKImageView` during image loading.
  18. */
  19. @property (nonatomic, assign) BOOL sd_adjustContentMode API_UNAVAILABLE(macos);
  20. /**
  21. * Set the imageView `image` with an `url`.
  22. *
  23. * The download is asynchronous and cached.
  24. *
  25. * @param url The url for the image.
  26. */
  27. - (void)sd_setImageWithURL:(nullable NSURL *)url NS_REFINED_FOR_SWIFT;
  28. /**
  29. * Set the imageView `image` with an `url` and a placeholder.
  30. *
  31. * The download is asynchronous and cached.
  32. *
  33. * @param url The url for the image.
  34. * @param placeholder The image to be set initially, until the image request finishes.
  35. * @see sd_setImageWithURL:placeholderImage:options:
  36. */
  37. - (void)sd_setImageWithURL:(nullable NSURL *)url
  38. placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  39. /**
  40. * Set the imageView `image` with an `url`, placeholder and custom options.
  41. *
  42. * The download is asynchronous and cached.
  43. *
  44. * @param url The url for the image.
  45. * @param placeholder The image to be set initially, until the image request finishes.
  46. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  47. */
  48. - (void)sd_setImageWithURL:(nullable NSURL *)url
  49. placeholderImage:(nullable UIImage *)placeholder
  50. options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
  51. /**
  52. * Set the imageView `image` with an `url`, placeholder, custom options and context.
  53. *
  54. * The download is asynchronous and cached.
  55. *
  56. * @param url The url for the image.
  57. * @param placeholder The image to be set initially, until the image request finishes.
  58. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  59. * @param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
  60. */
  61. - (void)sd_setImageWithURL:(nullable NSURL *)url
  62. placeholderImage:(nullable UIImage *)placeholder
  63. options:(SDWebImageOptions)options
  64. context:(nullable SDWebImageContext *)context;
  65. /**
  66. * Set the imageView `image` with an `url`.
  67. *
  68. * The download is asynchronous and cached.
  69. *
  70. * @param url The url for the image.
  71. * @param completedBlock A block called when operation has been completed. This block has no return value
  72. * and takes the requested UIImage as first parameter. In case of error the image parameter
  73. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  74. * indicating if the image was retrieved from the local cache or from the network.
  75. * The fourth parameter is the original image url.
  76. */
  77. - (void)sd_setImageWithURL:(nullable NSURL *)url
  78. completed:(nullable SDExternalCompletionBlock)completedBlock;
  79. /**
  80. * Set the imageView `image` with an `url`, placeholder.
  81. *
  82. * The download is asynchronous and cached.
  83. *
  84. * @param url The url for the image.
  85. * @param placeholder The image to be set initially, until the image request finishes.
  86. * @param completedBlock A block called when operation has been completed. This block has no return value
  87. * and takes the requested UIImage as first parameter. In case of error the image parameter
  88. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  89. * indicating if the image was retrieved from the local cache or from the network.
  90. * The fourth parameter is the original image url.
  91. */
  92. - (void)sd_setImageWithURL:(nullable NSURL *)url
  93. placeholderImage:(nullable UIImage *)placeholder
  94. completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  95. /**
  96. * Set the imageView `image` with an `url`, placeholder and custom options.
  97. *
  98. * The download is asynchronous and cached.
  99. *
  100. * @param url The url for the image.
  101. * @param placeholder The image to be set initially, until the image request finishes.
  102. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  103. * @param completedBlock A block called when operation has been completed. This block has no return value
  104. * and takes the requested UIImage as first parameter. In case of error the image parameter
  105. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  106. * indicating if the image was retrieved from the local cache or from the network.
  107. * The fourth parameter is the original image url.
  108. */
  109. - (void)sd_setImageWithURL:(nullable NSURL *)url
  110. placeholderImage:(nullable UIImage *)placeholder
  111. options:(SDWebImageOptions)options
  112. completed:(nullable SDExternalCompletionBlock)completedBlock;
  113. /**
  114. * Set the imageView `image` with an `url`, placeholder and custom options.
  115. *
  116. * The download is asynchronous and cached.
  117. *
  118. * @param url The url for the image.
  119. * @param placeholder The image to be set initially, until the image request finishes.
  120. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  121. * @param progressBlock A block called while image is downloading
  122. * @note the progress block is executed on a background queue
  123. * @param completedBlock A block called when operation has been completed. This block has no return value
  124. * and takes the requested UIImage as first parameter. In case of error the image parameter
  125. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  126. * indicating if the image was retrieved from the local cache or from the network.
  127. * The fourth parameter is the original image url.
  128. */
  129. - (void)sd_setImageWithURL:(nullable NSURL *)url
  130. placeholderImage:(nullable UIImage *)placeholder
  131. options:(SDWebImageOptions)options
  132. progress:(nullable SDImageLoaderProgressBlock)progressBlock
  133. completed:(nullable SDExternalCompletionBlock)completedBlock;
  134. /**
  135. * Set the imageView `image` with an `url`, placeholder, custom options and context.
  136. *
  137. * The download is asynchronous and cached.
  138. *
  139. * @param url The url for the image.
  140. * @param placeholder The image to be set initially, until the image request finishes.
  141. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  142. * @param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
  143. * @param progressBlock A block called while image is downloading
  144. * @note the progress block is executed on a background queue
  145. * @param completedBlock A block called when operation has been completed. This block has no return value
  146. * and takes the requested UIImage as first parameter. In case of error the image parameter
  147. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  148. * indicating if the image was retrieved from the local cache or from the network.
  149. * The fourth parameter is the original image url.
  150. */
  151. - (void)sd_setImageWithURL:(nullable NSURL *)url
  152. placeholderImage:(nullable UIImage *)placeholder
  153. options:(SDWebImageOptions)options
  154. context:(nullable SDWebImageContext *)context
  155. progress:(nullable SDImageLoaderProgressBlock)progressBlock
  156. completed:(nullable SDExternalCompletionBlock)completedBlock;
  157. @end
  158. NS_ASSUME_NONNULL_END