TWMessageBarManager.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // TWMessageBarManager.h
  3. //
  4. // Created by Terry Worona on 5/13/13.
  5. // Copyright (c) 2013 Terry Worona. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <UIKit/UIKit.h>
  9. /**
  10. * Three base message bar types. Their look & feel is defined within the MessageBarStyleSheet.
  11. */
  12. typedef NS_ENUM(NSInteger, TWMessageBarMessageType) {
  13. TWMessageBarMessageTypeError,
  14. TWMessageBarMessageTypeSuccess,
  15. TWMessageBarMessageTypeInfo
  16. };
  17. @protocol TWMessageBarStyleSheet <NSObject>
  18. /**
  19. * Background color of message view.
  20. *
  21. * @param type A MessageBarMessageType (error, information, success, etc).
  22. *
  23. * @return UIColor istance representing the message view's background color.
  24. */
  25. - (nonnull UIColor *)backgroundColorForMessageType:(TWMessageBarMessageType)type;
  26. /**
  27. * Bottom stroke color of message view.
  28. *
  29. * @param type A MessageBarMessageType (error, information, success, etc).
  30. *
  31. * @return UIColor istance representing the message view's bottom stroke color.
  32. */
  33. - (nonnull UIColor *)strokeColorForMessageType:(TWMessageBarMessageType)type;
  34. /**
  35. * Icon image of the message view.
  36. *
  37. * @param type A MessageBarMessageType (error, information, success, etc).
  38. *
  39. * @return UIImage istance representing the message view's icon.
  40. */
  41. - (nonnull UIImage *)iconImageForMessageType:(TWMessageBarMessageType)type;
  42. @optional
  43. /**
  44. * The (optional) UIFont to be used for the message's title.
  45. *
  46. * Default: 16pt bold
  47. *
  48. * @param type A MessageBarMessageType (error, information, success, etc).
  49. *
  50. * @return UIFont instance representing the title font.
  51. */
  52. - (nonnull UIFont *)titleFontForMessageType:(TWMessageBarMessageType)type;
  53. /**
  54. * The (optional) UIFont to be used for the message's description.
  55. *
  56. * Default: 14pt regular
  57. *
  58. * @param type A MessageBarMessageType (error, information, success, etc).
  59. *
  60. * @return UIFont instance representing the description font.
  61. */
  62. - (nonnull UIFont *)descriptionFontForMessageType:(TWMessageBarMessageType)type;
  63. /**
  64. * The (optional) UIColor to be used for the message's title.
  65. *
  66. * Default: white
  67. *
  68. * @param type A MessageBarMessageType (error, information, success, etc).
  69. *
  70. * @return UIColor instance representing the title color.
  71. */
  72. - (nonnull UIColor *)titleColorForMessageType:(TWMessageBarMessageType)type;
  73. /**
  74. * The (optional) UIColor to be used for the message's description.
  75. *
  76. * Default: white
  77. *
  78. * @param type A MessageBarMessageType (error, information, success, etc).
  79. *
  80. * @return UIColor instance representing the description color.
  81. */
  82. - (nonnull UIColor *)descriptionColorForMessageType:(TWMessageBarMessageType)type;
  83. @end
  84. @interface TWMessageBarManager : NSObject
  85. /**
  86. * Singleton instance through which all presentation is managed.
  87. *
  88. * @return MessageBarManager instance (singleton).
  89. */
  90. + (nonnull TWMessageBarManager *)sharedInstance;
  91. /**
  92. * Default display duration for each message.
  93. * This can be customized on a per-message basis (see presentation functions below).
  94. *
  95. * @return Default display duration (3 seconds).
  96. */
  97. + (CGFloat)defaultDuration;
  98. /**
  99. * Flag indicating if message is currently visible on screen.
  100. */
  101. @property (nonatomic, readonly, getter = isMessageVisible) BOOL messageVisible;
  102. /**
  103. * The orientations supported by the manager.
  104. * In most cases, this value will match the caller's orientation mask.
  105. *
  106. * @return Default behaviour - all orientations.
  107. */
  108. @property (nonatomic, assign) UIInterfaceOrientationMask managerSupportedOrientationsMask;
  109. /**
  110. * An object conforming to the TWMessageBarStyleSheet protocol defines the message bar's look and feel.
  111. * If no style sheet is supplied, a default class is provided on initialization (see implementation for details).
  112. */
  113. @property (nonnull, nonatomic, strong) NSObject<TWMessageBarStyleSheet> *styleSheet;
  114. /**
  115. * Shows a message with the supplied title, description and type.
  116. *
  117. * @param title Header text in the message view.
  118. * @param description Description text in the message view.
  119. * @param type Type dictates color, stroke and icon shown in the message view.
  120. */
  121. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type;
  122. /**
  123. * Shows a message with the supplied title, description, type & callback block.
  124. *
  125. * @param title Header text in the message view.
  126. * @param description Description text in the message view.
  127. * @param type Type dictates color, stroke and icon shown in the message view.
  128. * @param callback Callback block to be executed if a message is tapped.
  129. */
  130. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type callback:(nullable void (^)())callback;
  131. /**
  132. * Shows a message with the supplied title, description, type & duration.
  133. *
  134. * @param title Header text in the message view.
  135. * @param description Description text in the message view.
  136. * @param type Type dictates color, stroke and icon shown in the message view.
  137. * @param duration Default duration is 3 seconds, this can be overridden by supplying an optional duration parameter.
  138. */
  139. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type duration:(CGFloat)duration;
  140. /**
  141. * Shows a message with the supplied title, description, type, duration and callback block.
  142. *
  143. * @param title Header text in the message view.
  144. * @param description Description text in the message view.
  145. * @param type Type dictates color, stroke and icon shown in the message view.
  146. * @param duration Default duration is 3 seconds, this can be overridden by supplying an optional duration parameter.
  147. * @param callback Callback block to be executed if a message is tapped.
  148. */
  149. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type duration:(CGFloat)duration callback:(nullable void (^)())callback;
  150. /**
  151. * Shows a message with the supplied title, description, type, status bar style and callback block.
  152. *
  153. * @param title Header text in the message view.
  154. * @param description Description text in the message view.
  155. * @param type Type dictates color, stroke and icon shown in the message view.
  156. * @param statusBarStyle Applied during the presentation of the message. If not supplied, style will default to UIStatusBarStyleDefault.
  157. * @param callback Callback block to be executed if a message is tapped.
  158. */
  159. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type statusBarStyle:(UIStatusBarStyle)statusBarStyle callback:(nullable void (^)())callback;
  160. /**
  161. * Shows a message with the supplied title, description, type, duration, status bar style and callback block.
  162. *
  163. * @param title Header text in the message view.
  164. * @param description Description text in the message view.
  165. * @param type Type dictates color, stroke and icon shown in the message view.
  166. * @param duration Default duration is 3 seconds, this can be overridden by supplying an optional duration parameter.
  167. * @param statusBarStyle Applied during the presentation of the message. If not supplied, style will default to UIStatusBarStyleDefault.
  168. * @param callback Callback block to be executed if a message is tapped.
  169. */
  170. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type duration:(CGFloat)duration statusBarStyle:(UIStatusBarStyle)statusBarStyle callback:(nullable void (^)())callback;
  171. /**
  172. * Shows a message with the supplied title, description, type, status bar hidden toggle and callback block.
  173. *
  174. * @param title Header text in the message view.
  175. * @param description Description text in the message view.
  176. * @param type Type dictates color, stroke and icon shown in the message view.
  177. * @param statusBarHidden Status bars are shown by default. To hide it during the presentation of a message, set to NO.
  178. * @param callback Callback block to be executed if a message is tapped.
  179. */
  180. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type statusBarHidden:(BOOL)statusBarHidden callback:(nullable void (^)())callback;
  181. /**
  182. * Shows a message with the supplied title, description, type, duration, status bar hidden toggle and callback block.
  183. *
  184. * @param title Header text in the message view.
  185. * @param description Description text in the message view.
  186. * @param type Type dictates color, stroke and icon shown in the message view.
  187. * @param duration Default duration is 3 seconds, this can be overridden by supplying an optional duration parameter.
  188. * @param statusBarHidden Status bars are shown by default. To hide it during the presentation of a message, set to NO.
  189. * @param callback Callback block to be executed if a message is tapped.
  190. */
  191. - (void)showMessageWithTitle:(nullable NSString *)title description:(nullable NSString *)description type:(TWMessageBarMessageType)type duration:(CGFloat)duration statusBarHidden:(BOOL)statusBarHidden callback:(nullable void (^)())callback;
  192. /**
  193. * Hides the topmost message and removes all remaining messages in the queue.
  194. *
  195. * @param animated Animates the current message view off the screen.
  196. */
  197. - (void)hideAllAnimated:(BOOL)animated;
  198. - (void)hideAll; // non-animated
  199. @end
  200. @interface UIDevice (Additions)
  201. /**
  202. * Determines if the device instance is running iOS 7 or later.
  203. *
  204. * @return YES if the device instance is running an OS >= 7, otherwise NO.
  205. */
  206. - (BOOL)tw_isRunningiOS7OrLater;
  207. @end