SMSSDKUIProcessHUD.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // BBSUIProcessHUD.m
  3. // BBSSDKUI
  4. //
  5. // Created by youzu_Max on 2017/4/25.
  6. // Copyright © 2017年 MOB. All rights reserved.
  7. //
  8. #import "SMSSDKUIProcessHUD.h"
  9. @interface SMSSDKUIProcessHUD()
  10. @property (nonatomic, strong) UIWindow *window;
  11. @property (nonatomic, strong) UIVisualEffectView *backgroundView;
  12. @property (nonatomic, strong) UILabel *alertLabel;
  13. @property (nonatomic, strong) UIImageView *processView;
  14. @property (nonatomic, strong) UIImage *failedImage;
  15. @property (nonatomic, strong) UIImage *successImage;
  16. @property (nonatomic, strong) UIActivityIndicatorView *inditorView;
  17. @end
  18. @implementation SMSSDKUIProcessHUD
  19. + (instancetype)shareInstance
  20. {
  21. static SMSSDKUIProcessHUD *shareInstance = nil ;
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. shareInstance = [[SMSSDKUIProcessHUD alloc] init];
  25. });
  26. return shareInstance ;
  27. }
  28. - (void)setup
  29. {
  30. self.window =
  31. ({
  32. CGSize size = [UIScreen mainScreen].bounds.size ;
  33. UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake((size.width-179)/2.0,size.height/2.0-109,179, 109)];
  34. window.backgroundColor = [UIColor clearColor];
  35. window.windowLevel = UIWindowLevelAlert + 1 ;
  36. window;
  37. });
  38. self.backgroundView =
  39. ({
  40. UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  41. UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
  42. effectview.frame = CGRectMake(0, 0, 179, 109);
  43. effectview.layer.cornerRadius = 12;
  44. effectview.layer.masksToBounds = YES;
  45. effectview.alpha = 0.75;
  46. [_window addSubview:effectview];
  47. effectview;
  48. });
  49. self.successImage =
  50. ({
  51. UIImage *successImage = [UIImage imageNamed:@"success@3x.png"];
  52. successImage ;
  53. });
  54. self.failedImage =
  55. ({
  56. UIImage *failedImage = [UIImage imageNamed:@"error@3x.png"];
  57. failedImage;
  58. });
  59. self.processView =
  60. ({
  61. UIImageView *processView = [[UIImageView alloc] initWithImage:_successImage];
  62. processView.center = _backgroundView.center;
  63. [_backgroundView.contentView addSubview:processView];
  64. processView;
  65. });
  66. self.alertLabel =
  67. ({
  68. UILabel *alertLabel = [[UILabel alloc] init];
  69. alertLabel.text = @"" ;
  70. alertLabel.textColor = [UIColor blackColor];
  71. alertLabel.font = [UIFont systemFontOfSize:14];
  72. alertLabel.frame = CGRectMake(0, 0, 155, 44);
  73. alertLabel.center = CGPointMake(90,88);
  74. alertLabel.numberOfLines = 0;
  75. alertLabel.textAlignment = NSTextAlignmentCenter;
  76. [_backgroundView.contentView addSubview:alertLabel];;
  77. alertLabel;
  78. });
  79. self.inditorView =
  80. ({
  81. UIActivityIndicatorView *inditorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  82. inditorView.center = _processView.center;
  83. inditorView.color = [UIColor blackColor];
  84. [_backgroundView.contentView addSubview:inditorView];
  85. inditorView;
  86. });
  87. }
  88. + (void) showSuccessInfo:(NSString *)info
  89. {
  90. SMSSDKUIProcessHUD *hud = [SMSSDKUIProcessHUD shareInstance];
  91. if(!hud.window)
  92. {
  93. [hud setup];
  94. }
  95. hud.alertLabel.text = info;
  96. hud.alertLabel.center = CGPointMake(90,88);
  97. hud.processView.image = hud.successImage;
  98. if (hud.processView.isHidden)
  99. {
  100. hud.processView.hidden = NO;
  101. }
  102. if (!hud.inditorView.isHidden)
  103. {
  104. hud.inditorView.hidden = YES;
  105. }
  106. if (hud.inditorView.isAnimating)
  107. {
  108. [hud.inditorView stopAnimating];
  109. }
  110. [hud.window makeKeyAndVisible];
  111. }
  112. + (void) showFailInfo:(NSString *)info
  113. {
  114. SMSSDKUIProcessHUD *hud = [SMSSDKUIProcessHUD shareInstance];
  115. if(!hud.window)
  116. {
  117. [hud setup];
  118. }
  119. hud.alertLabel.text = info;
  120. hud.alertLabel.center = CGPointMake(90,88);
  121. hud.processView.image = hud.failedImage;
  122. if (hud.processView.isHidden)
  123. {
  124. hud.processView.hidden = NO;
  125. }
  126. if (!hud.inditorView.isHidden)
  127. {
  128. hud.inditorView.hidden = YES;
  129. }
  130. if (hud.inditorView.isAnimating)
  131. {
  132. [hud.inditorView stopAnimating];
  133. }
  134. [hud.window makeKeyAndVisible];
  135. }
  136. + (void) showProcessHUDWithInfo:(NSString *)info
  137. {
  138. SMSSDKUIProcessHUD *hud = [SMSSDKUIProcessHUD shareInstance];
  139. if(!hud.window)
  140. {
  141. [hud setup];
  142. }
  143. hud.alertLabel.text = info;
  144. hud.alertLabel.center = CGPointMake(90,88);
  145. if (!hud.processView.isHidden)
  146. {
  147. hud.processView.hidden = YES;
  148. }
  149. if (hud.inditorView.isHidden)
  150. {
  151. hud.inditorView.hidden = NO;
  152. }
  153. if (!hud.inditorView.isAnimating)
  154. {
  155. [hud.inditorView startAnimating];
  156. }
  157. [hud.window makeKeyAndVisible];
  158. }
  159. + (void) dismiss
  160. {
  161. [[SMSSDKUIProcessHUD shareInstance].window resignKeyWindow];
  162. [SMSSDKUIProcessHUD shareInstance].window = nil;
  163. }
  164. + (void)dismissWithResult:(void (^)())result
  165. {
  166. [self dismiss];
  167. if (result)
  168. {
  169. result();
  170. }
  171. }
  172. + (void)dismissWithDelay:(NSTimeInterval)second result:(void (^)())result
  173. {
  174. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(second * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  175. [self dismissWithResult:result];
  176. });
  177. }
  178. @end