SVProgressHUD.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // SVProgressHUD.h
  3. // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
  4. //
  5. // Copyright (c) 2011-2018 Sam Vermette and contributors. All rights reserved.
  6. //
  7. #import <UIKit/UIKit.h>
  8. #import <AvailabilityMacros.h>
  9. extern NSString * _Nonnull const SVProgressHUDDidReceiveTouchEventNotification;
  10. extern NSString * _Nonnull const SVProgressHUDDidTouchDownInsideNotification;
  11. extern NSString * _Nonnull const SVProgressHUDWillDisappearNotification;
  12. extern NSString * _Nonnull const SVProgressHUDDidDisappearNotification;
  13. extern NSString * _Nonnull const SVProgressHUDWillAppearNotification;
  14. extern NSString * _Nonnull const SVProgressHUDDidAppearNotification;
  15. extern NSString * _Nonnull const SVProgressHUDStatusUserInfoKey;
  16. typedef NS_ENUM(NSInteger, SVProgressHUDStyle) {
  17. SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred
  18. SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred
  19. SVProgressHUDStyleCustom // uses the fore- and background color properties
  20. };
  21. typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {
  22. SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed
  23. SVProgressHUDMaskTypeClear, // don't allow user interactions with background objects
  24. SVProgressHUDMaskTypeBlack, // don't allow user interactions with background objects and dim the UI in the back of the HUD (as seen in iOS 7 and above)
  25. SVProgressHUDMaskTypeGradient, // don't allow user interactions with background objects and dim the UI with a a-la UIAlertView background gradient (as seen in iOS 6)
  26. SVProgressHUDMaskTypeCustom // don't allow user interactions with background objects and dim the UI in the back of the HUD with a custom color
  27. };
  28. typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) {
  29. SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring)
  30. SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView
  31. };
  32. typedef void (^SVProgressHUDShowCompletion)(void);
  33. typedef void (^SVProgressHUDDismissCompletion)(void);
  34. @interface SVProgressHUD : UIView
  35. #pragma mark - Customization
  36. @property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight
  37. @property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone
  38. @property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat
  39. @property (strong, nonatomic, nullable) UIView *containerView; // if nil then use default window level
  40. @property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message
  41. @property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt
  42. @property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt
  43. @property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt
  44. @property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt
  45. @property (strong, nonatomic, nonnull) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
  46. @property (strong, nonatomic, nonnull) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor whiteColor]
  47. @property (strong, nonatomic, nonnull) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor]
  48. @property (strong, nonatomic, nonnull) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR;// default is [UIColor colorWithWhite:0 alpha:0.4]
  49. @property (assign, nonatomic) CGSize imageViewSize UI_APPEARANCE_SELECTOR; // default is 28x28 pt
  50. @property (assign, nonatomic) BOOL shouldTintImages UI_APPEARANCE_SELECTOR; // default is YES
  51. @property (strong, nonatomic, nonnull) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik
  52. @property (strong, nonatomic, nonnull) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik
  53. @property (strong, nonatomic, nonnull) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik
  54. @property (strong, nonatomic, nonnull) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set
  55. @property (assign, nonatomic) NSTimeInterval graceTimeInterval; // default is 0 seconds
  56. @property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds
  57. @property (assign, nonatomic) NSTimeInterval maximumDismissTimeInterval; // default is CGFLOAT_MAX
  58. @property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0
  59. @property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15
  60. @property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15
  61. @property (assign, nonatomic) UIWindowLevel maxSupportedWindowLevel; // default is UIWindowLevelNormal
  62. @property (assign, nonatomic) BOOL hapticsEnabled; // default is NO
  63. + (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
  64. + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
  65. + (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
  66. + (void)setContainerView:(nullable UIView*)containerView; // default is window level
  67. + (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
  68. + (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt
  69. + (void)setRingRadius:(CGFloat)radius; // default is 18 pt
  70. + (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
  71. + (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
  72. + (void)setBorderColor:(nonnull UIColor*)color; // default is nil
  73. + (void)setBorderWidth:(CGFloat)width; // default is 0
  74. + (void)setFont:(nonnull UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
  75. + (void)setForegroundColor:(nonnull UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
  76. + (void)setBackgroundColor:(nonnull UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
  77. + (void)setBackgroundLayerColor:(nonnull UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.5], only used for SVProgressHUDMaskTypeCustom
  78. + (void)setImageViewSize:(CGSize)size; // default is 28x28 pt
  79. + (void)setShouldTintImages:(BOOL)shouldTintImages; // default is YES
  80. + (void)setInfoImage:(nonnull UIImage*)image; // default is the bundled info image provided by Freepik
  81. + (void)setSuccessImage:(nonnull UIImage*)image; // default is the bundled success image provided by Freepik
  82. + (void)setErrorImage:(nonnull UIImage*)image; // default is the bundled error image provided by Freepik
  83. + (void)setViewForExtension:(nonnull UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
  84. + (void)setGraceTimeInterval:(NSTimeInterval)interval; // default is 0 seconds
  85. + (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
  86. + (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval; // default is infinite
  87. + (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
  88. + (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
  89. + (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal
  90. + (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
  91. #pragma mark - Show Methods
  92. + (void)show;
  93. + (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
  94. + (void)showWithStatus:(nullable NSString*)status;
  95. + (void)showWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead.")));
  96. + (void)showProgress:(float)progress;
  97. + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead.")));
  98. + (void)showProgress:(float)progress status:(nullable NSString*)status;
  99. + (void)showProgress:(float)progress status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress:status: and setDefaultMaskType: instead.")));
  100. + (void)setStatus:(nullable NSString*)status; // change the HUD loading status while it's showing
  101. // stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later
  102. + (void)showInfoWithStatus:(nullable NSString*)status;
  103. + (void)showInfoWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead.")));
  104. + (void)showSuccessWithStatus:(nullable NSString*)status;
  105. + (void)showSuccessWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead.")));
  106. + (void)showErrorWithStatus:(nullable NSString*)status;
  107. + (void)showErrorWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead.")));
  108. // shows a image + status, use white PNGs with the imageViewSize (default is 28x28 pt)
  109. + (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status;
  110. + (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage:status: and setDefaultMaskType: instead.")));
  111. + (void)setOffsetFromCenter:(UIOffset)offset;
  112. + (void)resetOffsetFromCenter;
  113. + (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed
  114. + (void)dismiss;
  115. + (void)dismissWithCompletion:(nullable SVProgressHUDDismissCompletion)completion;
  116. + (void)dismissWithDelay:(NSTimeInterval)delay;
  117. + (void)dismissWithDelay:(NSTimeInterval)delay completion:(nullable SVProgressHUDDismissCompletion)completion;
  118. + (BOOL)isVisible;
  119. + (NSTimeInterval)displayDurationForString:(nullable NSString*)string;
  120. @end