MBProgressHUD+DS.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. + (void)showAutoMessage:(NSString *)message{
  39. [self showAutoMessage:message ToView:nil];
  40. }
  41. //自动消失提示,无图
  42. + (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{
  43. [self showMessage:message ToView:view RemainTime:2 Model:MBProgressHUDModeText];
  44. }
  45. //自定义停留时间,有图
  46. +(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  47. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate];
  48. }
  49. //自定义停留时间,无图
  50. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{
  51. [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText];
  52. }
  53. +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{
  54. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  55. // 快速显示一个提示信息
  56. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  57. hud.detailsLabel.text = message;
  58. //模式
  59. hud.mode = model;
  60. // 隐藏时候从父控件中移除
  61. hud.removeFromSuperViewOnHide = YES;
  62. hud.userInteractionEnabled = NO;
  63. // YES代表需要蒙版效果
  64. // hud.dimBackground = YES;
  65. // hud.backgroundColor = [];
  66. // if ([[NSThread currentThread] isEqual:[NSThread mainThread]]) {
  67. // hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
  68. // hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:.2f];
  69. // }
  70. // X秒之后再消失
  71. [hud hideAnimated:YES afterDelay:time];
  72. }
  73. + (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view
  74. {
  75. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  76. // 快速显示一个提示信息
  77. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  78. hud.label.text = title;
  79. // 设置图片
  80. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]];
  81. // 再设置模式
  82. hud.mode = MBProgressHUDModeCustomView;
  83. // 隐藏时候从父控件中移除
  84. hud.removeFromSuperViewOnHide = YES;
  85. // 2秒之后再消失
  86. [hud hideAnimated:YES afterDelay:2.1];
  87. hud.userInteractionEnabled = NO;
  88. }
  89. + (void)hideHUDForView:(UIView *)view
  90. {
  91. if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;
  92. [self hideHUDForView:view animated:YES];
  93. }
  94. + (void)hideHUD
  95. {
  96. [self hideHUDForView:nil];
  97. }
  98. @end