酷店

UIScrollView+EmptyDataSet.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. //
  2. // UIScrollView+EmptyDataSet.h
  3. // DZNEmptyDataSet
  4. // https://github.com/dzenbot/DZNEmptyDataSet
  5. //
  6. // Created by Ignacio Romero Zurbuchen on 6/20/14.
  7. // Copyright (c) 2016 DZN Labs. All rights reserved.
  8. // Licence: MIT-Licence
  9. //
  10. #import <UIKit/UIKit.h>
  11. @protocol DZNEmptyDataSetSource;
  12. @protocol DZNEmptyDataSetDelegate;
  13. #define DZNEmptyDataSetDeprecated(instead) DEPRECATED_MSG_ATTRIBUTE(" Use " # instead " instead")
  14. /**
  15. A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display.
  16. @discussion It will work automatically, by just conforming to DZNEmptyDataSetSource, and returning the data you want to show.
  17. */
  18. @interface UIScrollView (EmptyDataSet)
  19. /** The empty datasets data source. */
  20. @property (nonatomic, weak) IBOutlet id <DZNEmptyDataSetSource> emptyDataSetSource;
  21. /** The empty datasets delegate. */
  22. @property (nonatomic, weak) IBOutlet id <DZNEmptyDataSetDelegate> emptyDataSetDelegate;
  23. /** YES if any empty dataset is visible. */
  24. @property (nonatomic, readonly, getter = isEmptyDataSetVisible) BOOL emptyDataSetVisible;
  25. /**
  26. Reloads the empty dataset content receiver.
  27. @discussion Call this method to force all the data to refresh. Calling -reloadData is similar, but this forces only the empty dataset to reload, not the entire table view or collection view.
  28. */
  29. - (void)reloadEmptyDataSet;
  30. @end
  31. /**
  32. The object that acts as the data source of the empty datasets.
  33. @discussion The data source must adopt the DZNEmptyDataSetSource protocol. The data source is not retained. All data source methods are optional.
  34. */
  35. @protocol DZNEmptyDataSetSource <NSObject>
  36. @optional
  37. /**
  38. Asks the data source for the title of the dataset.
  39. The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.
  40. @param scrollView A scrollView subclass informing the data source.
  41. @return An attributed string for the dataset title, combining font, text color, text pararaph style, etc.
  42. */
  43. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView;
  44. /**
  45. Asks the data source for the description of the dataset.
  46. The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.
  47. @param scrollView A scrollView subclass informing the data source.
  48. @return An attributed string for the dataset description text, combining font, text color, text pararaph style, etc.
  49. */
  50. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView;
  51. /**
  52. Asks the data source for the image of the dataset.
  53. @param scrollView A scrollView subclass informing the data source.
  54. @return An image for the dataset.
  55. */
  56. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView;
  57. /**
  58. Asks the data source for a tint color of the image dataset. Default is nil.
  59. @param scrollView A scrollView subclass object informing the data source.
  60. @return A color to tint the image of the dataset.
  61. */
  62. - (UIColor *)imageTintColorForEmptyDataSet:(UIScrollView *)scrollView;
  63. /**
  64. * Asks the data source for the image animation of the dataset.
  65. *
  66. * @param scrollView A scrollView subclass object informing the delegate.
  67. *
  68. * @return image animation
  69. */
  70. - (CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView;
  71. /**
  72. Asks the data source for the title to be used for the specified button state.
  73. The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string.
  74. @param scrollView A scrollView subclass object informing the data source.
  75. @param state The state that uses the specified title. The possible values are described in UIControlState.
  76. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc.
  77. */
  78. - (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state;
  79. /**
  80. Asks the data source for the image to be used for the specified button state.
  81. This method will override buttonTitleForEmptyDataSet:forState: and present the image only without any text.
  82. @param scrollView A scrollView subclass object informing the data source.
  83. @param state The state that uses the specified title. The possible values are described in UIControlState.
  84. @return An image for the dataset button imageview.
  85. */
  86. - (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state;
  87. /**
  88. Asks the data source for a background image to be used for the specified button state.
  89. There is no default style for this call.
  90. @param scrollView A scrollView subclass informing the data source.
  91. @param state The state that uses the specified image. The values are described in UIControlState.
  92. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc.
  93. */
  94. - (UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state;
  95. /**
  96. Asks the data source for the background color of the dataset. Default is clear color.
  97. @param scrollView A scrollView subclass object informing the data source.
  98. @return A color to be applied to the dataset background view.
  99. */
  100. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView;
  101. /**
  102. Asks the data source for a custom view to be displayed instead of the default views such as labels, imageview and button. Default is nil.
  103. Use this method to show an activity view indicator for loading feedback, or for complete custom empty data set.
  104. Returning a custom view will ignore -offsetForEmptyDataSet and -spaceHeightForEmptyDataSet configurations.
  105. @param scrollView A scrollView subclass object informing the delegate.
  106. @return The custom view.
  107. */
  108. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView;
  109. /**
  110. Asks the data source for a offset for vertical and horizontal alignment of the content. Default is CGPointZero.
  111. @param scrollView A scrollView subclass object informing the delegate.
  112. @return The offset for vertical and horizontal alignment.
  113. */
  114. - (CGPoint)offsetForEmptyDataSet:(UIScrollView *)scrollView DZNEmptyDataSetDeprecated(-verticalOffsetForEmptyDataSet:);
  115. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView;
  116. /**
  117. Asks the data source for a vertical space between elements. Default is 11 pts.
  118. @param scrollView A scrollView subclass object informing the delegate.
  119. @return The space height between elements.
  120. */
  121. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView;
  122. @end
  123. /**
  124. The object that acts as the delegate of the empty datasets.
  125. @discussion The delegate can adopt the DZNEmptyDataSetDelegate protocol. The delegate is not retained. All delegate methods are optional.
  126. @discussion All delegate methods are optional. Use this delegate for receiving action callbacks.
  127. */
  128. @protocol DZNEmptyDataSetDelegate <NSObject>
  129. @optional
  130. /**
  131. Asks the delegate to know if the empty dataset should fade in when displayed. Default is YES.
  132. @param scrollView A scrollView subclass object informing the delegate.
  133. @return YES if the empty dataset should fade in.
  134. */
  135. - (BOOL)emptyDataSetShouldFadeIn:(UIScrollView *)scrollView;
  136. /**
  137. Asks the delegate to know if the empty dataset should still be displayed when the amount of items is more than 0. Default is NO
  138. @param scrollView A scrollView subclass object informing the delegate.
  139. @return YES if empty dataset should be forced to display
  140. */
  141. - (BOOL)emptyDataSetShouldBeForcedToDisplay:(UIScrollView *)scrollView;
  142. /**
  143. Asks the delegate to know if the empty dataset should be rendered and displayed. Default is YES.
  144. @param scrollView A scrollView subclass object informing the delegate.
  145. @return YES if the empty dataset should show.
  146. */
  147. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView;
  148. /**
  149. Asks the delegate for touch permission. Default is YES.
  150. @param scrollView A scrollView subclass object informing the delegate.
  151. @return YES if the empty dataset receives touch gestures.
  152. */
  153. - (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView;
  154. /**
  155. Asks the delegate for scroll permission. Default is NO.
  156. @param scrollView A scrollView subclass object informing the delegate.
  157. @return YES if the empty dataset is allowed to be scrollable.
  158. */
  159. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView;
  160. /**
  161. Asks the delegate for image view animation permission. Default is NO.
  162. Make sure to return a valid CAAnimation object from imageAnimationForEmptyDataSet:
  163. @param scrollView A scrollView subclass object informing the delegate.
  164. @return YES if the empty dataset is allowed to animate
  165. */
  166. - (BOOL)emptyDataSetShouldAnimateImageView:(UIScrollView *)scrollView;
  167. /**
  168. Tells the delegate that the empty dataset view was tapped.
  169. Use this method either to resignFirstResponder of a textfield or searchBar.
  170. @param scrollView A scrollView subclass informing the delegate.
  171. */
  172. - (void)emptyDataSetDidTapView:(UIScrollView *)scrollView DZNEmptyDataSetDeprecated(-emptyDataSet:didTapView:);
  173. /**
  174. Tells the delegate that the action button was tapped.
  175. @param scrollView A scrollView subclass informing the delegate.
  176. */
  177. - (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView DZNEmptyDataSetDeprecated(-emptyDataSet:didTapButton:);
  178. /**
  179. Tells the delegate that the empty dataset view was tapped.
  180. Use this method either to resignFirstResponder of a textfield or searchBar.
  181. @param scrollView A scrollView subclass informing the delegate.
  182. @param view the view tapped by the user
  183. */
  184. - (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view;
  185. /**
  186. Tells the delegate that the action button was tapped.
  187. @param scrollView A scrollView subclass informing the delegate.
  188. @param button the button tapped by the user
  189. */
  190. - (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button;
  191. /**
  192. Tells the delegate that the empty data set will appear.
  193. @param scrollView A scrollView subclass informing the delegate.
  194. */
  195. - (void)emptyDataSetWillAppear:(UIScrollView *)scrollView;
  196. /**
  197. Tells the delegate that the empty data set did appear.
  198. @param scrollView A scrollView subclass informing the delegate.
  199. */
  200. - (void)emptyDataSetDidAppear:(UIScrollView *)scrollView;
  201. /**
  202. Tells the delegate that the empty data set will disappear.
  203. @param scrollView A scrollView subclass informing the delegate.
  204. */
  205. - (void)emptyDataSetWillDisappear:(UIScrollView *)scrollView;
  206. /**
  207. Tells the delegate that the empty data set did disappear.
  208. @param scrollView A scrollView subclass informing the delegate.
  209. */
  210. - (void)emptyDataSetDidDisappear:(UIScrollView *)scrollView;
  211. @end
  212. #undef DZNEmptyDataSetDeprecated