酷店

MBProgressHUD+KDPCategory.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // MBProgressHUD+KDPCategory.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "MBProgressHUD+KDPCategory.h"
  9. @implementation MBProgressHUD (KDPCategory)
  10. #pragma mark 显示一条信息
  11. + (void)showMessage:(NSString *)message toView:(UIView *)view{
  12. [self show:message icon:nil view:view];
  13. }
  14. #pragma mark 显示带图片或者不带图片的信息
  15. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view{
  16. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  17. // 快速显示一个提示信息
  18. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  19. hud.labelText = text;
  20. // 判断是否显示图片
  21. if (icon == nil) {
  22. hud.mode = MBProgressHUDModeText;
  23. }else{
  24. // 设置图片
  25. UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]];
  26. img = img == nil ? [UIImage imageNamed:icon] : img;
  27. hud.customView = [[UIImageView alloc] initWithImage:img];
  28. // 再设置模式
  29. hud.mode = MBProgressHUDModeCustomView;
  30. }
  31. // 隐藏时候从父控件中移除
  32. hud.removeFromSuperViewOnHide = YES;
  33. // 指定时间之后再消失
  34. [hud hide:YES afterDelay:kHudShowTime];
  35. }
  36. #pragma mark 显示成功信息
  37. + (void)showSuccess:(NSString *)success toView:(UIView *)view{
  38. [self show:success icon:@"success.png" view:view];
  39. }
  40. #pragma mark 显示错误信息
  41. + (void)showError:(NSString *)error toView:(UIView *)view{
  42. [self show:error icon:@"error.png" view:view];
  43. }
  44. #pragma mark 显示警告信息
  45. + (void)showWarning:(NSString *)Warning toView:(UIView *)view{
  46. [self show:Warning icon:@"warn" view:view];
  47. }
  48. #pragma mark 显示自定义图片信息
  49. + (void)showMessageWithImageName:(NSString *)imageName message:(NSString *)message toView:(UIView *)view{
  50. [self show:message icon:imageName view:view];
  51. }
  52. #pragma mark 加载中
  53. + (MBProgressHUD *)showActivityMessage:(NSString*)message view:(UIView *)view{
  54. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  55. // 快速显示一个提示信息
  56. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  57. hud.labelText = message;
  58. // 细节文字
  59. // hud.detailsLabelText = @"请耐心等待";
  60. // 再设置模式
  61. hud.mode = MBProgressHUDModeIndeterminate;
  62. // 隐藏时候从父控件中移除
  63. hud.removeFromSuperViewOnHide = YES;
  64. return hud;
  65. }
  66. + (MBProgressHUD *)showProgressBarToView:(UIView *)view{
  67. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  68. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  69. hud.mode = MBProgressHUDModeDeterminate;
  70. hud.labelText = @"加载中...";
  71. return hud;
  72. }
  73. + (void)showMessage:(NSString *)message{
  74. [self showMessage:message toView:nil];
  75. }
  76. + (void)showSuccess:(NSString *)success{
  77. [self showSuccess:success toView:nil];
  78. }
  79. + (void)showError:(NSString *)error{
  80. [self showError:error toView:nil];
  81. }
  82. + (void)showWarning:(NSString *)Warning{
  83. [self showWarning:Warning toView:nil];
  84. }
  85. + (void)showMessageWithImageName:(NSString *)imageName message:(NSString *)message{
  86. [self showMessageWithImageName:imageName message:message toView:nil];
  87. }
  88. + (MBProgressHUD *)showActivityMessage:(NSString*)message{
  89. return [self showActivityMessage:message view:nil];
  90. }
  91. + (void)hideHUDForView:(UIView *)view{
  92. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  93. [self hideHUDForView:view animated:YES];
  94. }
  95. + (void)hideHUD{
  96. [self hideHUDForView:nil];
  97. }
  98. @end