MBProgressHUD+DS.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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:@"mbp_error.png" Title:error ToView:view];
  13. }
  14. + (void)showSuccess:(NSString *)success ToView:(UIView *)view {
  15. [self showCustomIcon:@"mbp_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. if ([[NSThread currentThread] isEqual:[NSThread mainThread]]) {
  28. hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
  29. hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
  30. }
  31. return hud;
  32. }
  33. //加载视图
  34. +(void)showLoadToView:(UIView *)view{
  35. [self showMessage:@"加载中..." ToView:view];
  36. }
  37. /**
  38. * 进度条View
  39. */
  40. + (MBProgressHUD *)showProgressToView:(UIView *)view ProgressModel:(MBProgressHUDMode)model Text:(NSString *)text{
  41. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  42. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  43. hud.mode = model;
  44. hud.label.text = text;
  45. return hud;
  46. }
  47. //快速显示一条提示信息
  48. + (void)showAutoMessage:(NSString *)message{
  49. [self showAutoMessage:message ToView:nil];
  50. }
  51. //自动消失提示,无图
  52. + (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{
  53. [self showMessage:message ToView:view RemainTime:2 Model:MBProgressHUDModeText];
  54. }
  55. //自定义停留时间,有图
  56. +(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  57. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate];
  58. }
  59. //自定义停留时间,无图
  60. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  61. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText];
  62. }
  63. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{
  64. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  65. // 快速显示一个提示信息
  66. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  67. hud.detailsLabel.text = message;
  68. //模式
  69. hud.mode = model;
  70. // 隐藏时候从父控件中移除
  71. hud.removeFromSuperViewOnHide = YES;
  72. hud.userInteractionEnabled = NO;
  73. // YES代表需要蒙版效果
  74. // hud.dimBackground = YES;
  75. // hud.backgroundColor = [];
  76. // if ([[NSThread currentThread] isEqual:[NSThread mainThread]]) {
  77. // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
  78. // hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
  79. // }
  80. // X秒之后再消失
  81. [hud hideAnimated:YES afterDelay:time];
  82. }
  83. + (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view
  84. {
  85. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  86. // 快速显示一个提示信息
  87. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  88. hud.label.text = title;
  89. // 设置图片
  90. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]];
  91. // 再设置模式
  92. hud.mode = MBProgressHUDModeCustomView;
  93. // 隐藏时候从父控件中移除
  94. hud.removeFromSuperViewOnHide = YES;
  95. // 2秒之后再消失
  96. [hud hideAnimated:YES afterDelay:2.1];
  97. hud.userInteractionEnabled = NO;
  98. }
  99. + (void)hideHUDForView:(UIView *)view
  100. {
  101. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  102. [self hideHUDForView:view animated:NO];
  103. }
  104. + (void)hideHUD
  105. {
  106. [self hideHUDForView:nil];
  107. }
  108. @end
  109. void ShowMsg(NSString *str){
  110. [MBProgressHUD showAutoMessage:str];
  111. }
  112. #pragma mark 确定弹框提示
  113. void showMsgByAlert(UIViewController *vc,NSString *str)
  114. {
  115. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
  116. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  117. [vc presentViewController:alertFind animated:true completion:nil];
  118. }
  119. void ShowErrorMsg(NSString *str){
  120. [MBProgressHUD showError:str ToView:nil];
  121. }
  122. void showMsgUnconnect(){
  123. ShowMsg(@"网络未连接");
  124. }