MBProgressHUD+YanC.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // MBProgressHUD+YanC.m
  3. // BorrowMoney
  4. //
  5. // Created by chengzhang Yan on 2016/10/13.
  6. // Copyright © 2016年 JuYi. All rights reserved.
  7. //
  8. #import "MBProgressHUD+YanC.h"
  9. @implementation MBProgressHUD (YanC)
  10. #pragma mark 显示信息
  11. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
  12. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  13. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  14. hud.label.text = text;
  15. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
  16. [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.8]];
  17. hud.contentColor = [UIColor whiteColor];
  18. hud.mode = MBProgressHUDModeCustomView;
  19. hud.removeFromSuperViewOnHide = YES;
  20. [hud hideAnimated:YES afterDelay:2.0];
  21. }
  22. /** 显示成功 */
  23. + (void)showSuccess:(NSString *)success {
  24. [self showSuccess:success toView:nil];
  25. }
  26. /** 显示失败 */
  27. + (void)showError:(NSString *)error {
  28. [self showError:error toView:nil];
  29. }
  30. /** 显示提示符号 */
  31. + (void)showInfo:(NSString *)info {
  32. [self showInfo:info toView:nil];
  33. }
  34. /** 显示信息+转圈圈 */
  35. + (void)showMessage:(NSString *)message {
  36. [self showMessage:message toView:nil];
  37. }
  38. /** 显示图片 */
  39. + (void)showLogoImageWithImageName:(NSString *)imgName {
  40. [self showLogoImageWithImageName:imgName toView:nil];
  41. //只显示菊花。因为没有了 gif 之后可以再改
  42. // [self showMessage:nil toView:nil model:MBProgressHUDModeIndeterminate];
  43. }
  44. /** 只显示一条提示信息 */
  45. + (void)showOnlyText:(NSString *)message {
  46. [self showOnlyText:message toView:nil];
  47. }
  48. /** 显示成功--->到指定view */
  49. + (void)showSuccess:(NSString *)success toView:(UIView *)view {
  50. [self show:success icon:@"success.png" view:view];
  51. }
  52. /** 显示失败--->到指定view */
  53. + (void)showError:(NSString *)error toView:(UIView *)view {
  54. [self show:error icon:@"error.png" view:view];
  55. }
  56. /** 显示提示符号--->到指定view */
  57. + (void)showInfo:(NSString *)info toView:(UIView *)view {
  58. [self show:info icon:@"info.png" view:view];
  59. }
  60. /** 显示信息(转圈圈)--->到指定view */
  61. + (void)showMessage:(NSString *)message toView:(UIView *)view {
  62. if (view == nil) {
  63. [self showMessage:message toView:view model:MBProgressHUDModeText];
  64. } else {
  65. [self showMessage:message toView:view model:MBProgressHUDModeCustomView];
  66. }
  67. }
  68. /** 只显示一条提示信息--->到指定view */
  69. + (void)showOnlyText:(NSString *)message toView:(UIView *)view {
  70. [self showMessage:message toView:view model:MBProgressHUDModeText];
  71. }
  72. + (void)showMessage:(NSString *)message toView:(UIView *)view model:(MBProgressHUDMode)model {
  73. // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  74. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  75. // 快速显示一个提示信息
  76. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  77. hud.labelText = message;
  78. //模式
  79. hud.mode = model;
  80. // YES代表需要蒙版效果
  81. hud.dimBackground = YES;
  82. // hud.backgroundColor = [UIColor colorWithWhite:0.f alpha:.2f];
  83. // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
  84. // 隐藏时候从父控件中移除
  85. hud.removeFromSuperViewOnHide = YES;
  86. if (model == MBProgressHUDModeText) {
  87. // X秒之后再消失
  88. [hud hide:YES afterDelay:2.0];
  89. }
  90. if (model == MBProgressHUDModeIndeterminate) {
  91. [hud hide:YES afterDelay:30.0];
  92. }
  93. }
  94. /** 显示图片 --->到指定view */
  95. + (void)showLogoImageWithImageName:(NSString *)imageName toView:(UIView *)view {
  96. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  97. // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  98. //
  99. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  100. UIImageView *imgBgView = [[UIImageView alloc] init];
  101. imgBgView.center = hud.customView.center;
  102. imgBgView.image = [UIImage imageNamed:imageName];
  103. hud.customView = imgBgView;
  104. // hud.dimBackground = YES;
  105. // hud.backgroundColor = [UIColor colorWithWhite:0.f alpha:.2f];
  106. // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
  107. hud.square = YES;
  108. hud.removeFromSuperViewOnHide = YES;
  109. hud.animationType = MBProgressHUDAnimationZoom;
  110. hud.mode = MBProgressHUDModeCustomView;
  111. hud.margin = 45.0f;
  112. hud.minSize = CGSizeMake(44.0f, 44.0f);
  113. // 消失时间
  114. [hud hide:YES afterDelay:30.0];
  115. }
  116. /** 隐藏HUD */
  117. + (void)hideHUD {
  118. [self hideHUDForView:nil];
  119. }
  120. /** 隐藏--->指定view上的HUD */
  121. + (void)hideHUDForView:(UIView *)view {
  122. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  123. // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  124. [self hideHUDForView:view animated:YES];
  125. }
  126. /** 只显示一条提示信息带确定按钮 */ //新需求
  127. + (void)showOnlyText:(NSString *)message controller:(UIViewController *)controller {
  128. //
  129. dispatch_async(dispatch_get_main_queue(), ^{
  130. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:(UIAlertControllerStyleAlert)];
  131. // 设置按钮
  132. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
  133. }];
  134. [alertController addAction:action1];
  135. [controller presentViewController:alertController animated:YES completion:nil];
  136. });
  137. }
  138. @end