MBProgressHUD+MJ.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // MBProgressHUD+MJ.m
  3. //
  4. // Created by mj on 13-4-18.
  5. // Copyright (c) 2013年 itcast. All rights reserved.
  6. //
  7. #import "MBProgressHUD+MJ.h"
  8. @implementation MBProgressHUD (MJ)
  9. #pragma mark 显示信息
  10. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
  11. {
  12. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  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. // 再设置模式
  19. hud.mode = MBProgressHUDModeCustomView;
  20. // 隐藏时候从父控件中移除
  21. hud.removeFromSuperViewOnHide = YES;
  22. // 1秒之后再消失
  23. [hud hideAnimated:YES afterDelay:0.7];
  24. }
  25. #pragma mark 显示错误信息
  26. + (void)showError:(NSString *)error toView:(UIView *)view
  27. {
  28. [self show:error icon:@"error.png" view:view];
  29. }
  30. + (void)showSuccess:(NSString *)success toView:(UIView *)view
  31. {
  32. [self show:success icon:@"success.png" view:view];
  33. }
  34. #pragma mark 显示一些信息
  35. + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view
  36. {
  37. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  38. // 快速显示一个提示信息
  39. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  40. hud.userInteractionEnabled = NO;
  41. hud.label.text = message;
  42. // 隐藏时候从父控件中移除
  43. hud.removeFromSuperViewOnHide = YES;
  44. // YES代表需要蒙版效果
  45. // hud.dimBackground = YES;
  46. return hud;
  47. }
  48. + (void)showSuccess:(NSString *)success
  49. {
  50. [self showSuccess:success toView:nil];
  51. }
  52. + (void)showError:(NSString *)error
  53. {
  54. [self showError:error toView:nil];
  55. }
  56. + (MBProgressHUD *)showMessage:(NSString *)message
  57. {
  58. return [self showMessage:message toView:nil];
  59. }
  60. + (void)hideHUDForView:(UIView *)view
  61. {
  62. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  63. [self hideHUDForView:view animated:YES];
  64. }
  65. + (void)hideHUD
  66. {
  67. [self hideHUDForView:nil];
  68. }
  69. @end