UIButton+YYWebImage.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // UIButton+YYWebImage.h
  3. // YYWebImage <https://github.com/ibireme/YYWebImage>
  4. //
  5. // Created by ibireme on 15/2/23.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #if __has_include(<YYWebImage/YYWebImage.h>)
  13. #import <YYWebImage/YYWebImageManager.h>
  14. #else
  15. #import "YYWebImageManager.h"
  16. #endif
  17. /**
  18. Web image methods for UIButton.
  19. */
  20. @interface UIButton (YYWebImage)
  21. #pragma mark - image
  22. /**
  23. Current image URL for the specified state.
  24. @return The image URL, or nil.
  25. */
  26. - (NSURL *)yy_imageURLForState:(UIControlState)state;
  27. /**
  28. Set the button's image with a specified URL for the specified state.
  29. @param imageURL The image url (remote or local file path).
  30. @param state The state that uses the specified image.
  31. @param placeholder The image to be set initially, until the image request finishes.
  32. */
  33. - (void)yy_setImageWithURL:(NSURL *)imageURL
  34. forState:(UIControlState)state
  35. placeholder:(UIImage *)placeholder;
  36. /**
  37. Set the button's image with a specified URL for the specified state.
  38. @param imageURL The image url (remote or local file path).
  39. @param state The state that uses the specified image.
  40. @param options The options to use when request the image.
  41. */
  42. - (void)yy_setImageWithURL:(NSURL *)imageURL
  43. forState:(UIControlState)state
  44. options:(YYWebImageOptions)options;
  45. /**
  46. Set the button's image with a specified URL for the specified state.
  47. @param imageURL The image url (remote or local file path).
  48. @param state The state that uses the specified image.
  49. @param placeholder The image to be set initially, until the image request finishes.
  50. @param options The options to use when request the image.
  51. @param completion The block invoked (on main thread) when image request completed.
  52. */
  53. - (void)yy_setImageWithURL:(NSURL *)imageURL
  54. forState:(UIControlState)state
  55. placeholder:(UIImage *)placeholder
  56. options:(YYWebImageOptions)options
  57. completion:(YYWebImageCompletionBlock)completion;
  58. /**
  59. Set the button's image with a specified URL for the specified state.
  60. @param imageURL The image url (remote or local file path).
  61. @param state The state that uses the specified image.
  62. @param placeholder The image to be set initially, until the image request finishes.
  63. @param options The options to use when request the image.
  64. @param progress The block invoked (on main thread) during image request.
  65. @param transform The block invoked (on background thread) to do additional image process.
  66. @param completion The block invoked (on main thread) when image request completed.
  67. */
  68. - (void)yy_setImageWithURL:(NSURL *)imageURL
  69. forState:(UIControlState)state
  70. placeholder:(UIImage *)placeholder
  71. options:(YYWebImageOptions)options
  72. progress:(YYWebImageProgressBlock)progress
  73. transform:(YYWebImageTransformBlock)transform
  74. completion:(YYWebImageCompletionBlock)completion;
  75. /**
  76. Set the button's image with a specified URL for the specified state.
  77. @param imageURL The image url (remote or local file path).
  78. @param state The state that uses the specified image.
  79. @param placeholder The image to be set initially, until the image request finishes.
  80. @param options The options to use when request the image.
  81. @param manager The manager to create image request operation.
  82. @param progress The block invoked (on main thread) during image request.
  83. @param transform The block invoked (on background thread) to do additional image process.
  84. @param completion The block invoked (on main thread) when image request completed.
  85. */
  86. - (void)yy_setImageWithURL:(NSURL *)imageURL
  87. forState:(UIControlState)state
  88. placeholder:(UIImage *)placeholder
  89. options:(YYWebImageOptions)options
  90. manager:(YYWebImageManager *)manager
  91. progress:(YYWebImageProgressBlock)progress
  92. transform:(YYWebImageTransformBlock)transform
  93. completion:(YYWebImageCompletionBlock)completion;
  94. /**
  95. Cancel the current image request for a specified state.
  96. @param state The state that uses the specified image.
  97. */
  98. - (void)yy_cancelImageRequestForState:(UIControlState)state;
  99. #pragma mark - background image
  100. /**
  101. Current backgroundImage URL for the specified state.
  102. @return The image URL, or nil.
  103. */
  104. - (NSURL *)yy_backgroundImageURLForState:(UIControlState)state;
  105. /**
  106. Set the button's backgroundImage with a specified URL for the specified state.
  107. @param imageURL The image url (remote or local file path).
  108. @param state The state that uses the specified image.
  109. @param placeholder The image to be set initially, until the image request finishes.
  110. */
  111. - (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
  112. forState:(UIControlState)state
  113. placeholder:(UIImage *)placeholder;
  114. /**
  115. Set the button's backgroundImage with a specified URL for the specified state.
  116. @param imageURL The image url (remote or local file path).
  117. @param state The state that uses the specified image.
  118. @param options The options to use when request the image.
  119. */
  120. - (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
  121. forState:(UIControlState)state
  122. options:(YYWebImageOptions)options;
  123. /**
  124. Set the button's backgroundImage with a specified URL for the specified state.
  125. @param imageURL The image url (remote or local file path).
  126. @param state The state that uses the specified image.
  127. @param placeholder The image to be set initially, until the image request finishes.
  128. @param options The options to use when request the image.
  129. @param completion The block invoked (on main thread) when image request completed.
  130. */
  131. - (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
  132. forState:(UIControlState)state
  133. placeholder:(UIImage *)placeholder
  134. options:(YYWebImageOptions)options
  135. completion:(YYWebImageCompletionBlock)completion;
  136. /**
  137. Set the button's backgroundImage with a specified URL for the specified state.
  138. @param imageURL The image url (remote or local file path).
  139. @param state The state that uses the specified image.
  140. @param placeholder The image to be set initially, until the image request finishes.
  141. @param options The options to use when request the image.
  142. @param progress The block invoked (on main thread) during image request.
  143. @param transform The block invoked (on background thread) to do additional image process.
  144. @param completion The block invoked (on main thread) when image request completed.
  145. */
  146. - (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
  147. forState:(UIControlState)state
  148. placeholder:(UIImage *)placeholder
  149. options:(YYWebImageOptions)options
  150. progress:(YYWebImageProgressBlock)progress
  151. transform:(YYWebImageTransformBlock)transform
  152. completion:(YYWebImageCompletionBlock)completion;
  153. /**
  154. Set the button's backgroundImage with a specified URL for the specified state.
  155. @param imageURL The image url (remote or local file path).
  156. @param state The state that uses the specified image.
  157. @param placeholder The image to be set initially, until the image request finishes.
  158. @param options The options to use when request the image.
  159. @param manager The manager to create image request operation.
  160. @param progress The block invoked (on main thread) during image request.
  161. @param transform The block invoked (on background thread) to do additional image process.
  162. @param completion The block invoked (on main thread) when image request completed.
  163. */
  164. - (void)yy_setBackgroundImageWithURL:(NSURL *)imageURL
  165. forState:(UIControlState)state
  166. placeholder:(UIImage *)placeholder
  167. options:(YYWebImageOptions)options
  168. manager:(YYWebImageManager *)manager
  169. progress:(YYWebImageProgressBlock)progress
  170. transform:(YYWebImageTransformBlock)transform
  171. completion:(YYWebImageCompletionBlock)completion;
  172. /**
  173. Cancel the current backgroundImage request for a specified state.
  174. @param state The state that uses the specified image.
  175. */
  176. - (void)yy_cancelBackgroundImageRequestForState:(UIControlState)state;
  177. @end