JDStatusBarNotification.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // JDStatusBarNotification.h
  3. //
  4. // Based on KGStatusBar by Kevin Gibbon
  5. //
  6. // Created by Markus Emrich on 10/28/13.
  7. // Copyright 2013 Markus Emrich. All rights reserved.
  8. //
  9. #import <UIKit/UIKit.h>
  10. #import "JDStatusBarStyle.h"
  11. #import "JDStatusBarView.h"
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. * A block that is used to define the appearance of a notification.
  15. * A JDStatusBarStyle instance defines the notification appeareance.
  16. *
  17. * @param style The current default JDStatusBarStyle instance.
  18. *
  19. * @return The modified JDStatusBarStyle instance.
  20. */
  21. typedef JDStatusBarStyle*(^JDPrepareStyleBlock)(JDStatusBarStyle *style);
  22. /**
  23. * This class is a singletion which is used to present notifications
  24. * on top of the status bar. To present a notification, use one of the
  25. * given class methods.
  26. */
  27. @interface JDStatusBarNotification : NSObject
  28. #pragma mark Presentation
  29. /**
  30. * Show a notification. It won't hide automatically,
  31. * you have to dimiss it on your own.
  32. *
  33. * @param status The message to display
  34. *
  35. * @return The presented notification view for further customization
  36. */
  37. + (JDStatusBarView*)showWithStatus:(NSString *)status;
  38. /**
  39. * Show a notification with a specific style. It won't
  40. * hide automatically, you have to dimiss it on your own.
  41. *
  42. * @param status The message to display
  43. * @param styleName The name of the style. You can use any JDStatusBarStyle constant
  44. * (JDStatusBarStyleDefault, etc.), or a custom style identifier, after you added a
  45. * custom style. If this is nil, the default style will be used.
  46. *
  47. * @return The presented notification view for further customization
  48. */
  49. + (JDStatusBarView*)showWithStatus:(NSString *)status
  50. styleName:(NSString*)styleName;
  51. /**
  52. * Same as showWithStatus:, but the notification will
  53. * automatically dismiss after the given timeInterval.
  54. *
  55. * @param status The message to display
  56. * @param timeInterval The duration, how long the notification
  57. * is displayed. (Including the animation duration)
  58. *
  59. * @return The presented notification view for further customization
  60. */
  61. + (JDStatusBarView*)showWithStatus:(NSString *)status
  62. dismissAfter:(NSTimeInterval)timeInterval;
  63. /**
  64. * Same as showWithStatus:styleName:, but the notification
  65. * will automatically dismiss after the given timeInterval.
  66. *
  67. * @param status The message to display
  68. * @param timeInterval The duration, how long the notification
  69. * is displayed. (Including the animation duration)
  70. * @param styleName The name of the style. You can use any JDStatusBarStyle constant
  71. * (JDStatusBarStyleDefault, etc.), or a custom style identifier, after you added a
  72. * custom style. If this is nil, the default style will be used.
  73. *
  74. * @return The presented notification view for further customization
  75. */
  76. + (JDStatusBarView*)showWithStatus:(NSString *)status
  77. dismissAfter:(NSTimeInterval)timeInterval
  78. styleName:(NSString*)styleName;
  79. #pragma mark Dismissal
  80. /**
  81. * Calls dismissAnimated: with animated set to YES
  82. */
  83. + (void)dismiss;
  84. /**
  85. * Dismisses any currently displayed notification immediately
  86. *
  87. * @param animated If this is YES, the animation style used
  88. * for presentation will also be used for the dismissal.
  89. */
  90. + (void)dismissAnimated:(BOOL)animated;
  91. /**
  92. * Same as dismissAnimated:, but you can specify a delay,
  93. * so the notification wont be dismissed immediately
  94. *
  95. * @param delay The delay, how long the notification should stay visible
  96. */
  97. + (void)dismissAfter:(NSTimeInterval)delay;
  98. #pragma mark Styles
  99. /**
  100. * This changes the default style, which is always used
  101. * when a method without styleName is used for presentation, or
  102. * styleName is nil, or no style is found with this name.
  103. *
  104. * @param prepareBlock A block, which has a JDStatusBarStyle instance as
  105. * parameter. This instance can be modified to suit your needs. You need
  106. * to return the modified style again.
  107. */
  108. + (void)setDefaultStyle:(JDPrepareStyleBlock)prepareBlock;
  109. /**
  110. * Adds a custom style, which than can be used
  111. * in the presentation methods.
  112. *
  113. * @param identifier The identifier, which will
  114. * later be used to reference the configured style.
  115. * @param prepareBlock A block, which has a JDStatusBarStyle instance as
  116. * parameter. This instance can be modified to suit your needs. You need
  117. * to return the modified style again.
  118. *
  119. * @return Returns the given identifier, so it can
  120. * be directly used as styleName parameter.
  121. */
  122. + (NSString*)addStyleNamed:(NSString*)identifier
  123. prepare:(JDPrepareStyleBlock)prepareBlock;
  124. #pragma mark Modifications
  125. /**
  126. * Update the text of the label without presenting a new notification.
  127. *
  128. * @param status The new message to display
  129. */
  130. + (void)updateStatus:(NSString *)status;
  131. /**
  132. * Show the progress below the label.
  133. *
  134. * @param progress Relative progress from 0.0 to 1.0
  135. */
  136. + (void)showProgress:(CGFloat)progress;
  137. /**
  138. * Shows an activity indicator in front of the notification text
  139. *
  140. * @param show Use this flag to show or hide the activity indicator
  141. * @param style Sets the style of the activity indicator
  142. */
  143. + (void)showActivityIndicator:(BOOL)show
  144. indicatorStyle:(UIActivityIndicatorViewStyle)style;
  145. #pragma mark state
  146. /**
  147. * This method tests, if a notification is currently displayed.
  148. *
  149. * @return YES, if a notification is currently displayed. Otherwise NO.
  150. */
  151. + (BOOL)isVisible;
  152. @end
  153. NS_ASSUME_NONNULL_END