UIButton+WebCache.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 "SDWebImageCompat.h"
  9. #if SD_UIKIT
  10. #import "SDWebImageManager.h"
  11. /**
  12. * Integrates SDWebImage async downloading and caching of remote images with UIButtonView.
  13. */
  14. @interface UIButton (WebCache)
  15. /**
  16. * Get the current image URL.
  17. */
  18. - (nullable NSURL *)sd_currentImageURL;
  19. #pragma mark - Image
  20. /**
  21. * Get the image URL for a control state.
  22. *
  23. * @param state Which state you want to know the URL for. The values are described in UIControlState.
  24. */
  25. - (nullable NSURL *)sd_imageURLForState:(UIControlState)state;
  26. /**
  27. * Set the imageView `image` with an `url`.
  28. *
  29. * The download is asynchronous and cached.
  30. *
  31. * @param url The url for the image.
  32. * @param state The state that uses the specified title. The values are described in UIControlState.
  33. */
  34. - (void)sd_setImageWithURL:(nullable NSURL *)url
  35. forState:(UIControlState)state;
  36. /**
  37. * Set the imageView `image` with an `url` and a placeholder.
  38. *
  39. * The download is asynchronous and cached.
  40. *
  41. * @param url The url for the image.
  42. * @param state The state that uses the specified title. The values are described in UIControlState.
  43. * @param placeholder The image to be set initially, until the image request finishes.
  44. * @see sd_setImageWithURL:placeholderImage:options:
  45. */
  46. - (void)sd_setImageWithURL:(nullable NSURL *)url
  47. forState:(UIControlState)state
  48. placeholderImage:(nullable UIImage *)placeholder;
  49. /**
  50. * Set the imageView `image` with an `url`, placeholder and custom options.
  51. *
  52. * The download is asynchronous and cached.
  53. *
  54. * @param url The url for the image.
  55. * @param state The state that uses the specified title. The values are described in UIControlState.
  56. * @param placeholder The image to be set initially, until the image request finishes.
  57. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  58. */
  59. - (void)sd_setImageWithURL:(nullable NSURL *)url
  60. forState:(UIControlState)state
  61. placeholderImage:(nullable UIImage *)placeholder
  62. options:(SDWebImageOptions)options;
  63. /**
  64. * Set the imageView `image` with an `url`.
  65. *
  66. * The download is asynchronous and cached.
  67. *
  68. * @param url The url for the image.
  69. * @param state The state that uses the specified title. The values are described in UIControlState.
  70. * @param completedBlock A block called when operation has been completed. This block has no return value
  71. * and takes the requested UIImage as first parameter. In case of error the image parameter
  72. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  73. * indicating if the image was retrieved from the local cache or from the network.
  74. * The fourth parameter is the original image url.
  75. */
  76. - (void)sd_setImageWithURL:(nullable NSURL *)url
  77. forState:(UIControlState)state
  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 state The state that uses the specified title. The values are described in UIControlState.
  86. * @param placeholder The image to be set initially, until the image request finishes.
  87. * @param completedBlock A block called when operation has been completed. This block has no return value
  88. * and takes the requested UIImage as first parameter. In case of error the image parameter
  89. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  90. * indicating if the image was retrieved from the local cache or from the network.
  91. * The fourth parameter is the original image url.
  92. */
  93. - (void)sd_setImageWithURL:(nullable NSURL *)url
  94. forState:(UIControlState)state
  95. placeholderImage:(nullable UIImage *)placeholder
  96. completed:(nullable SDExternalCompletionBlock)completedBlock;
  97. /**
  98. * Set the imageView `image` with an `url`, placeholder and custom options.
  99. *
  100. * The download is asynchronous and cached.
  101. *
  102. * @param url The url for the image.
  103. * @param state The state that uses the specified title. The values are described in UIControlState.
  104. * @param placeholder The image to be set initially, until the image request finishes.
  105. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  106. * @param completedBlock A block called when operation has been completed. This block has no return value
  107. * and takes the requested UIImage as first parameter. In case of error the image parameter
  108. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  109. * indicating if the image was retrieved from the local cache or from the network.
  110. * The fourth parameter is the original image url.
  111. */
  112. - (void)sd_setImageWithURL:(nullable NSURL *)url
  113. forState:(UIControlState)state
  114. placeholderImage:(nullable UIImage *)placeholder
  115. options:(SDWebImageOptions)options
  116. completed:(nullable SDExternalCompletionBlock)completedBlock;
  117. #pragma mark - Background image
  118. /**
  119. * Set the backgroundImageView `image` with an `url`.
  120. *
  121. * The download is asynchronous and cached.
  122. *
  123. * @param url The url for the image.
  124. * @param state The state that uses the specified title. The values are described in UIControlState.
  125. */
  126. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  127. forState:(UIControlState)state;
  128. /**
  129. * Set the backgroundImageView `image` with an `url` and a placeholder.
  130. *
  131. * The download is asynchronous and cached.
  132. *
  133. * @param url The url for the image.
  134. * @param state The state that uses the specified title. The values are described in UIControlState.
  135. * @param placeholder The image to be set initially, until the image request finishes.
  136. * @see sd_setImageWithURL:placeholderImage:options:
  137. */
  138. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  139. forState:(UIControlState)state
  140. placeholderImage:(nullable UIImage *)placeholder;
  141. /**
  142. * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  143. *
  144. * The download is asynchronous and cached.
  145. *
  146. * @param url The url for the image.
  147. * @param state The state that uses the specified title. The values are described in UIControlState.
  148. * @param placeholder The image to be set initially, until the image request finishes.
  149. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  150. */
  151. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  152. forState:(UIControlState)state
  153. placeholderImage:(nullable UIImage *)placeholder
  154. options:(SDWebImageOptions)options;
  155. /**
  156. * Set the backgroundImageView `image` with an `url`.
  157. *
  158. * The download is asynchronous and cached.
  159. *
  160. * @param url The url for the image.
  161. * @param state The state that uses the specified title. The values are described in UIControlState.
  162. * @param completedBlock A block called when operation has been completed. This block has no return value
  163. * and takes the requested UIImage as first parameter. In case of error the image parameter
  164. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  165. * indicating if the image was retrieved from the local cache or from the network.
  166. * The fourth parameter is the original image url.
  167. */
  168. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  169. forState:(UIControlState)state
  170. completed:(nullable SDExternalCompletionBlock)completedBlock;
  171. /**
  172. * Set the backgroundImageView `image` with an `url`, placeholder.
  173. *
  174. * The download is asynchronous and cached.
  175. *
  176. * @param url The url for the image.
  177. * @param state The state that uses the specified title. The values are described in UIControlState.
  178. * @param placeholder The image to be set initially, until the image request finishes.
  179. * @param completedBlock A block called when operation has been completed. This block has no return value
  180. * and takes the requested UIImage as first parameter. In case of error the image parameter
  181. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  182. * indicating if the image was retrieved from the local cache or from the network.
  183. * The fourth parameter is the original image url.
  184. */
  185. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  186. forState:(UIControlState)state
  187. placeholderImage:(nullable UIImage *)placeholder
  188. completed:(nullable SDExternalCompletionBlock)completedBlock;
  189. /**
  190. * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  191. *
  192. * The download is asynchronous and cached.
  193. *
  194. * @param url The url for the image.
  195. * @param placeholder The image to be set initially, until the image request finishes.
  196. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  197. * @param completedBlock A block called when operation has been completed. This block has no return value
  198. * and takes the requested UIImage as first parameter. In case of error the image parameter
  199. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  200. * indicating if the image was retrieved from the local cache or from the network.
  201. * The fourth parameter is the original image url.
  202. */
  203. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  204. forState:(UIControlState)state
  205. placeholderImage:(nullable UIImage *)placeholder
  206. options:(SDWebImageOptions)options
  207. completed:(nullable SDExternalCompletionBlock)completedBlock;
  208. #pragma mark - Cancel
  209. /**
  210. * Cancel the current image download
  211. */
  212. - (void)sd_cancelImageLoadForState:(UIControlState)state;
  213. /**
  214. * Cancel the current backgroundImage download
  215. */
  216. - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
  217. @end
  218. #endif