You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

205 lines
9.1 KiB

  1. //
  2. // TSMessage.h
  3. // Felix Krause
  4. //
  5. // Created by Felix Krause on 24.08.12.
  6. // Copyright (c) 2012 Felix Krause. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. // NS_ENUM is now the preferred way to do typedefs. It gives the compiler and debugger more information, which helps everyone.
  10. // When using SDK 6 or later, NS_ENUM is defined by Apple, so this block does nothing.
  11. // For SDK 5 or earlier, this is the same definition block Apple uses.
  12. #ifndef NS_ENUM
  13. #if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
  14. #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  15. #if (__cplusplus)
  16. #define NS_OPTIONS(_type, _name) _type _name; enum : _type
  17. #else
  18. #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  19. #endif
  20. #else
  21. #define NS_ENUM(_type, _name) _type _name; enum
  22. #define NS_OPTIONS(_type, _name) _type _name; enum
  23. #endif
  24. #endif
  25. #define TS_SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  26. @class TSMessageView;
  27. /** Define on which position a specific TSMessage should be displayed */
  28. @protocol TSMessageViewProtocol<NSObject>
  29. @optional
  30. /** Implement this method to pass a custom position for a specific message */
  31. - (CGFloat)messageLocationOfMessageView:(TSMessageView *)messageView;
  32. /** You can custimze the given TSMessageView, like setting its alpha or adding a subview */
  33. - (void)customizeMessageView:(TSMessageView *)messageView;
  34. @end
  35. typedef NS_ENUM(NSInteger, TSMessageNotificationType) {
  36. TSMessageNotificationTypeMessage = 0,
  37. TSMessageNotificationTypeWarning,
  38. TSMessageNotificationTypeError,
  39. TSMessageNotificationTypeSuccess
  40. };
  41. typedef NS_ENUM(NSInteger, TSMessageNotificationPosition) {
  42. TSMessageNotificationPositionTop = 0,
  43. TSMessageNotificationPositionNavBarOverlay,
  44. TSMessageNotificationPositionBottom
  45. };
  46. /** This enum can be passed to the duration parameter */
  47. typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) {
  48. TSMessageNotificationDurationAutomatic = 0,
  49. TSMessageNotificationDurationEndless = -1 // The notification is displayed until the user dismissed it or it is dismissed by calling dismissActiveNotification
  50. };
  51. @interface TSMessage : NSObject
  52. /** By setting this delegate it's possible to set a custom offset for the notification view */
  53. @property (nonatomic, assign) id <TSMessageViewProtocol>delegate;
  54. + (instancetype)sharedMessage;
  55. + (UIViewController *)defaultViewController;
  56. /** Shows a notification message
  57. @param message The title of the notification view
  58. @param type The notification type (Message, Warning, Error, Success)
  59. */
  60. + (void)showNotificationWithTitle:(NSString *)message
  61. type:(TSMessageNotificationType)type;
  62. /** Shows a notification message
  63. @param title The title of the notification view
  64. @param subtitle The text that is displayed underneath the title
  65. @param type The notification type (Message, Warning, Error, Success)
  66. */
  67. + (void)showNotificationWithTitle:(NSString *)title
  68. subtitle:(NSString *)subtitle
  69. type:(TSMessageNotificationType)type;
  70. /** Shows a notification message in a specific view controller
  71. @param viewController The view controller to show the notification in.
  72. You can use +setDefaultViewController: to set the the default one instead
  73. @param title The title of the notification view
  74. @param subtitle The text that is displayed underneath the title
  75. @param type The notification type (Message, Warning, Error, Success)
  76. */
  77. + (void)showNotificationInViewController:(UIViewController *)viewController
  78. title:(NSString *)title
  79. subtitle:(NSString *)subtitle
  80. type:(TSMessageNotificationType)type;
  81. /** Shows a notification message in a specific view controller with a specific duration
  82. @param viewController The view controller to show the notification in.
  83. You can use +setDefaultViewController: to set the the default one instead
  84. @param title The title of the notification view
  85. @param subtitle The text that is displayed underneath the title
  86. @param type The notification type (Message, Warning, Error, Success)
  87. @param duration The duration of the notification being displayed
  88. */
  89. + (void)showNotificationInViewController:(UIViewController *)viewController
  90. title:(NSString *)title
  91. subtitle:(NSString *)subtitle
  92. type:(TSMessageNotificationType)type
  93. duration:(NSTimeInterval)duration;
  94. /** Shows a notification message in a specific view controller with a specific duration
  95. @param viewController The view controller to show the notification in.
  96. You can use +setDefaultViewController: to set the the default one instead
  97. @param title The title of the notification view
  98. @param subtitle The text that is displayed underneath the title
  99. @param type The notification type (Message, Warning, Error, Success)
  100. @param duration The duration of the notification being displayed
  101. @param dismissingEnabled Should the message be dismissed when the user taps/swipes it
  102. */
  103. + (void)showNotificationInViewController:(UIViewController *)viewController
  104. title:(NSString *)title
  105. subtitle:(NSString *)subtitle
  106. type:(TSMessageNotificationType)type
  107. duration:(NSTimeInterval)duration
  108. canBeDismissedByUser:(BOOL)dismissingEnabled;
  109. /** Shows a notification message in a specific view controller
  110. @param viewController The view controller to show the notification in.
  111. @param title The title of the notification view
  112. @param subtitle The message that is displayed underneath the title (optional)
  113. @param image A custom icon image (optional)
  114. @param type The notification type (Message, Warning, Error, Success)
  115. @param duration The duration of the notification being displayed
  116. @param callback The block that should be executed, when the user tapped on the message
  117. @param buttonTitle The title for button (optional)
  118. @param buttonCallback The block that should be executed, when the user tapped on the button
  119. @param messagePosition The position of the message on the screen
  120. @param dismissingEnabled Should the message be dismissed when the user taps/swipes it
  121. */
  122. + (void)showNotificationInViewController:(UIViewController *)viewController
  123. title:(NSString *)title
  124. subtitle:(NSString *)subtitle
  125. image:(UIImage *)image
  126. type:(TSMessageNotificationType)type
  127. duration:(NSTimeInterval)duration
  128. callback:(void (^)())callback
  129. buttonTitle:(NSString *)buttonTitle
  130. buttonCallback:(void (^)())buttonCallback
  131. atPosition:(TSMessageNotificationPosition)messagePosition
  132. canBeDismissedByUser:(BOOL)dismissingEnabled;
  133. /** Fades out the currently displayed notification. If another notification is in the queue,
  134. the next one will be displayed automatically
  135. @return YES if the currently displayed notification was successfully dismissed. NO if no notification
  136. was currently displayed.
  137. */
  138. + (BOOL)dismissActiveNotification;
  139. /** Fades out the currently displayed notification with a completion block after the animation has finished. If another notification is in the queue,
  140. the next one will be displayed automatically
  141. @return YES if the currently displayed notification was successfully dismissed. NO if no notification
  142. was currently displayed.
  143. */
  144. + (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion;
  145. /** Use this method to set a default view controller to display the messages in */
  146. + (void)setDefaultViewController:(UIViewController *)defaultViewController;
  147. /** Set a delegate to have full control over the position of the message view */
  148. + (void)setDelegate:(id<TSMessageViewProtocol>)delegate;
  149. /** Use this method to use custom designs in your messages. */
  150. + (void)addCustomDesignFromFileWithName:(NSString *)fileName;
  151. /** Indicates whether a notification is currently active. */
  152. + (BOOL)isNotificationActive;
  153. /** Returns the currently queued array of TSMessageView */
  154. + (NSArray *)queuedMessages;
  155. /** Prepares the notification view to be displayed in the future. It is queued and then
  156. displayed in fadeInCurrentNotification.
  157. You don't have to use this method. */
  158. + (void)prepareNotificationToBeShown:(TSMessageView *)messageView;
  159. /** Indicates whether currently the iOS 7 style of TSMessages is used
  160. This depends on the Base SDK and the currently used device */
  161. + (BOOL)iOS7StyleEnabled;
  162. /** Indicates whether the current navigationBar is hidden by isNavigationBarHidden
  163. on the UINavigationController or isHidden on the navigationBar of the current
  164. UINavigationController */
  165. + (BOOL)isNavigationBarInNavigationControllerHidden:(UINavigationController *)navController;
  166. @end