UIButton+WebCache.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #pragma mark - Image
  16. /**
  17. * Get the current image URL.
  18. */
  19. - (nullable NSURL *)sd_currentImageURL;
  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 NS_REFINED_FOR_SWIFT;
  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 NS_REFINED_FOR_SWIFT;
  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 NS_REFINED_FOR_SWIFT;
  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 NS_REFINED_FOR_SWIFT;
  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. * Get the current background image URL.
  120. */
  121. - (nullable NSURL *)sd_currentBackgroundImageURL;
  122. /**
  123. * Get the background image URL for a control state.
  124. *
  125. * @param state Which state you want to know the URL for. The values are described in UIControlState.
  126. */
  127. - (nullable NSURL *)sd_backgroundImageURLForState:(UIControlState)state;
  128. /**
  129. * Set the backgroundImageView `image` with an `url`.
  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. */
  136. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  137. forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
  138. /**
  139. * Set the backgroundImageView `image` with an `url` and a placeholder.
  140. *
  141. * The download is asynchronous and cached.
  142. *
  143. * @param url The url for the image.
  144. * @param state The state that uses the specified title. The values are described in UIControlState.
  145. * @param placeholder The image to be set initially, until the image request finishes.
  146. * @see sd_setImageWithURL:placeholderImage:options:
  147. */
  148. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  149. forState:(UIControlState)state
  150. placeholderImage:(nullable UIImage *)placeholder NS_REFINED_FOR_SWIFT;
  151. /**
  152. * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  153. *
  154. * The download is asynchronous and cached.
  155. *
  156. * @param url The url for the image.
  157. * @param state The state that uses the specified title. The values are described in UIControlState.
  158. * @param placeholder The image to be set initially, until the image request finishes.
  159. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  160. */
  161. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  162. forState:(UIControlState)state
  163. placeholderImage:(nullable UIImage *)placeholder
  164. options:(SDWebImageOptions)options NS_REFINED_FOR_SWIFT;
  165. /**
  166. * Set the backgroundImageView `image` with an `url`.
  167. *
  168. * The download is asynchronous and cached.
  169. *
  170. * @param url The url for the image.
  171. * @param state The state that uses the specified title. The values are described in UIControlState.
  172. * @param completedBlock A block called when operation has been completed. This block has no return value
  173. * and takes the requested UIImage as first parameter. In case of error the image parameter
  174. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  175. * indicating if the image was retrieved from the local cache or from the network.
  176. * The fourth parameter is the original image url.
  177. */
  178. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  179. forState:(UIControlState)state
  180. completed:(nullable SDExternalCompletionBlock)completedBlock;
  181. /**
  182. * Set the backgroundImageView `image` with an `url`, placeholder.
  183. *
  184. * The download is asynchronous and cached.
  185. *
  186. * @param url The url for the image.
  187. * @param state The state that uses the specified title. The values are described in UIControlState.
  188. * @param placeholder The image to be set initially, until the image request finishes.
  189. * @param completedBlock A block called when operation has been completed. This block has no return value
  190. * and takes the requested UIImage as first parameter. In case of error the image parameter
  191. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  192. * indicating if the image was retrieved from the local cache or from the network.
  193. * The fourth parameter is the original image url.
  194. */
  195. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  196. forState:(UIControlState)state
  197. placeholderImage:(nullable UIImage *)placeholder
  198. completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT;
  199. /**
  200. * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  201. *
  202. * The download is asynchronous and cached.
  203. *
  204. * @param url The url for the image.
  205. * @param placeholder The image to be set initially, until the image request finishes.
  206. * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  207. * @param completedBlock A block called when operation has been completed. This block has no return value
  208. * and takes the requested UIImage as first parameter. In case of error the image parameter
  209. * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  210. * indicating if the image was retrieved from the local cache or from the network.
  211. * The fourth parameter is the original image url.
  212. */
  213. - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
  214. forState:(UIControlState)state
  215. placeholderImage:(nullable UIImage *)placeholder
  216. options:(SDWebImageOptions)options
  217. completed:(nullable SDExternalCompletionBlock)completedBlock;
  218. #pragma mark - Cancel
  219. /**
  220. * Cancel the current image download
  221. */
  222. - (void)sd_cancelImageLoadForState:(UIControlState)state;
  223. /**
  224. * Cancel the current backgroundImage download
  225. */
  226. - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
  227. @end
  228. #endif