MBProgressHUD+DS.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // MBProgressHUD+DS.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/6.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "MBProgressHUD+DS.h"
  9. @implementation MBProgressHUD (DS)
  10. #pragma mark 显示错误信息
  11. + (void)showError:(NSString *)error ToView:(UIView *)view {
  12. [self showCustomIcon:@"error.png" Title:error ToView:view];
  13. }
  14. + (void)showSuccess:(NSString *)success ToView:(UIView *)view {
  15. [self showCustomIcon:@"success.png" Title:success ToView:view];
  16. }
  17. #pragma mark 显示一些信息
  18. + (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view {
  19. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  20. // 快速显示一个提示信息
  21. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  22. hud.label.text= message;
  23. // 隐藏时候从父控件中移除
  24. hud.removeFromSuperViewOnHide = YES;
  25. // YES代表需要蒙版效果
  26. hud.dimBackground = YES;
  27. return hud;
  28. }
  29. //加载视图
  30. + (void)showLoadToView:(UIView *)view {
  31. [self showMessage:@"加载中..." ToView:view];
  32. }
  33. /**
  34. * 进度条View
  35. */
  36. + (MBProgressHUD *)showProgressToView:(UIView *)view ProgressModel:(MBProgressHUDMode)model Text:(NSString *)text{
  37. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  38. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  39. hud.mode = model;
  40. hud.label.text = text;
  41. return hud;
  42. }
  43. //快速显示一条提示信息
  44. + (void)showAutoMessage:(NSString *)message{
  45. [self showAutoMessage:message ToView:nil];
  46. }
  47. //自动消失提示,无图
  48. + (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{
  49. [self showMessage:message ToView:view RemainTime:2.1 Model:MBProgressHUDModeText];
  50. }
  51. //自定义停留时间,有图
  52. +(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  53. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate];
  54. }
  55. //自定义停留时间,无图
  56. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  57. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText];
  58. }
  59. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{
  60. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  61. // 快速显示一个提示信息
  62. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  63. hud.detailsLabel.text = message;
  64. //模式
  65. hud.mode = model;
  66. // 隐藏时候从父控件中移除
  67. hud.removeFromSuperViewOnHide = YES;
  68. // YES代表需要蒙版效果
  69. hud.dimBackground = YES;
  70. // 隐藏时候从父控件中移除
  71. hud.removeFromSuperViewOnHide = YES;
  72. // X秒之后再消失
  73. [hud hide:YES afterDelay:time];
  74. }
  75. + (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view
  76. {
  77. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  78. // 快速显示一个提示信息
  79. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  80. hud.label.text = title;
  81. // 设置图片
  82. if ([iconName isEqualToString:@"error.png"] || [iconName isEqualToString:@"success.png"]) {
  83. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", iconName]]];
  84. }else{
  85. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]];
  86. }
  87. // 再设置模式
  88. hud.mode = MBProgressHUDModeCustomView;
  89. // 隐藏时候从父控件中移除
  90. hud.removeFromSuperViewOnHide = YES;
  91. // 2秒之后再消失
  92. [hud hide:YES afterDelay:2.1];
  93. }
  94. + (void)hideHUDForView:(UIView *)view
  95. {
  96. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  97. [self hideHUDForView:view animated:YES];
  98. }
  99. + (void)hideHUD
  100. {
  101. [self hideHUDForView:nil];
  102. }
  103. @end
  104. void ShowHUD() {
  105. [MBProgressHUD showLoadToView:nil];
  106. }
  107. void RemoveHUD() {
  108. [MBProgressHUD hideHUD];
  109. }
  110. void ShowMsg(NSString *str) {
  111. [MBProgressHUD showAutoMessage:str];
  112. }
  113. void ShowErrorMsg(NSString *str) {
  114. [MBProgressHUD showError:str ToView:nil];
  115. }
  116. void ShowSuccessMsg(NSString *str) {
  117. [MBProgressHUD showSuccess:str ToView:nil];
  118. }
  119. void ShowMsgUnOpen() {
  120. [MBProgressHUD showAutoMessage:@"暂未开放,敬请期待"];
  121. }
  122. void showMsgUnconnect() {
  123. [MBProgressHUD showAutoMessage:@"网络未连接"];
  124. }
  125. void ShowMsgError() {
  126. [MBProgressHUD showError:@"操作失败" ToView:nil];
  127. }
  128. void ShowMsgSuccess() {
  129. [MBProgressHUD showCustomIcon:@"question_success.png" Title:@"操作成功" ToView:nil];
  130. //[MBProgressHUD showSuccess:@"操作成功" ToView:nil];
  131. }
  132. void showMsgByAlert(UIViewController *vc,NSString *str)
  133. {
  134. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  135. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  136. [vc presentViewController:alertFind animated:true completion:nil];
  137. }