MBProgressHUD+MJ.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #import "MBProgressHUD+MJ.h"
  2. @implementation MBProgressHUD (MJ)
  3. #pragma mark 显示信息
  4. +(void)showPop:(NSString *)text {
  5. [self showError:text withView:nil];
  6. }
  7. +(void)rkShowImgSuc:(NSString *)text {
  8. [self show:text icon:@"提示-勾" view:nil];
  9. }
  10. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
  11. //[[UIApplication sharedApplication].windows lastObject];
  12. if (view == nil) view = [[UIApplication sharedApplication].delegate window];
  13. // 快速显示一个提示信息
  14. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  15. hud.label.text = text;
  16. // 设置图片
  17. //hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
  18. hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:icon]];
  19. // 再设置模式
  20. hud.mode = MBProgressHUDModeCustomView;
  21. // 隐藏时候从父控件中移除
  22. hud.removeFromSuperViewOnHide = YES;
  23. hud.contentColor = [UIColor whiteColor];
  24. hud.bezelView.backgroundColor = [UIColor blackColor];
  25. hud.bezelView.alpha = 1;
  26. // 1秒之后再消失
  27. [hud hideAnimated:YES afterDelay:1.3];
  28. }
  29. #pragma mark 显示错误信息
  30. + (void)showError:(NSString *)error toView:(UIView *)view{
  31. [self show:error icon:@"error.png" view:view];
  32. }
  33. + (void)showSuccess:(NSString *)success toView:(UIView *)view
  34. {
  35. [self show:success icon:@"success.png" view:view];
  36. }
  37. #pragma mark 显示一些信息
  38. + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
  39. if (view == nil) view = [[UIApplication sharedApplication].delegate window];
  40. // 快速显示一个提示信息
  41. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  42. hud.label.text = message;
  43. // 隐藏时候从父控件中移除
  44. hud.removeFromSuperViewOnHide = YES;
  45. hud.contentColor = [UIColor whiteColor];
  46. hud.bezelView.backgroundColor = [UIColor blackColor];
  47. return hud;
  48. }
  49. + (void)showSuccess:(NSString *)success
  50. {
  51. [self showSuccess:success toView:[[UIApplication sharedApplication].delegate window]];
  52. }
  53. + (void)showError:(NSString *)error
  54. {
  55. //[self showError:error toView:[UIApplication sharedApplication].keyWindow];
  56. [self showError:error withView:nil];
  57. }
  58. + (void)showError:(NSString *)error withView:(UIView *)view{
  59. if (view == nil) view = [[UIApplication sharedApplication].delegate window];
  60. // 快速显示一个提示信息
  61. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  62. hud.label.text = error;
  63. hud.label.font = [UIFont systemFontOfSize:13];
  64. hud.label.numberOfLines = 0;
  65. hud.contentColor = [UIColor whiteColor];
  66. hud.bezelView.backgroundColor = [UIColor blackColor];
  67. hud.bezelView.alpha = 1;
  68. // 再设置模式
  69. hud.mode = MBProgressHUDModeCustomView;
  70. // 隐藏时候从父控件中移除
  71. hud.removeFromSuperViewOnHide = YES;
  72. [hud hideAnimated:YES afterDelay:1];
  73. }
  74. + (MBProgressHUD *)showMessage:(NSString *)message
  75. {
  76. [self hideHUD];
  77. return [self showMessage:message toView:[[UIApplication sharedApplication].delegate window]];
  78. }
  79. + (void)hideHUDForView:(UIView *)view
  80. {
  81. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  82. [self hideHUDForView:view animated:YES];
  83. // });
  84. }
  85. + (void)hideHUD
  86. {
  87. [self hideHUDForView:[[UIApplication sharedApplication].delegate window]];
  88. }
  89. @end