悟空记账

MBProgressHUD+Extension.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // MBProgressHUD+Extension.m
  3. // djlt
  4. //
  5. // Created by macmini04 on 16/1/18.
  6. // Copyright © 2016年 com.topsage.djlt. All rights reserved.
  7. //
  8. #import "MBProgressHUD+Extension.h"
  9. @implementation MBProgressHUD (Extension)
  10. + (instancetype)showLoadingAddedToView:(UIView *)view {
  11. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  12. hud.label.text = @"加载中";
  13. hud.label.textColor = [UIColor JZColorWithHex:0x333333];
  14. hud.label.font = [UIFont boldSystemFontOfSize:17];
  15. hud.bezelView.backgroundColor = [UIColor whiteColor];
  16. hud.bezelView.layer.cornerRadius = 14;
  17. hud.backgroundColor = [UIColor JZColorWithHex:0x000000 alpha:0.3];
  18. return hud;
  19. }
  20. + (instancetype)showTip:(NSString *)tip {
  21. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  22. hud.mode = MBProgressHUDModeText;
  23. hud.label.text = tip;
  24. hud.label.numberOfLines=0;
  25. hud.label.textColor = [UIColor whiteColor];
  26. hud.label.font = [UIFont boldSystemFontOfSize:17];
  27. hud.bezelView.backgroundColor = [UIColor blackColor];
  28. hud.bezelView.layer.cornerRadius = 14;
  29. hud.backgroundColor = [UIColor JZColorWithHex:0x000000 alpha:0.3];
  30. [hud hideAnimated:YES afterDelay:1.5];
  31. return hud;
  32. }
  33. + (instancetype)showTip:(NSString *)tip time:(NSTimeInterval)time {
  34. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  35. hud.mode = MBProgressHUDModeIndeterminate;
  36. hud.contentColor = [UIColor whiteColor];
  37. hud.label.text = tip;
  38. hud.label.numberOfLines=0;
  39. hud.label.textColor = [UIColor whiteColor];
  40. hud.label.font = [UIFont boldSystemFontOfSize:17];
  41. hud.bezelView.backgroundColor = [UIColor blackColor];
  42. hud.bezelView.layer.cornerRadius = 14;
  43. hud.backgroundColor = [UIColor JZColorWithHex:0x000000 alpha:0.3];
  44. [hud hideAnimated:YES afterDelay:time];
  45. return hud;
  46. }
  47. /** 显示信息 */
  48. + (MBProgressHUD *)showMessage:(NSString *)message {
  49. return [self showMessage:message toView:nil];
  50. }
  51. + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
  52. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  53. // 快速显示一个提示信息
  54. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  55. hud.label.text = message;
  56. hud.mode =MBProgressHUDModeText;
  57. // 隐藏时候从父控件中移除
  58. hud.removeFromSuperViewOnHide = YES;
  59. // 1秒之后再消失
  60. [hud hideAnimated:YES afterDelay:2];
  61. return hud;
  62. }
  63. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
  64. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  65. // 快速显示一个提示信息
  66. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  67. hud.label.text = text;
  68. // 设置图片
  69. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
  70. // 再设置模式
  71. hud.mode = MBProgressHUDModeCustomView;
  72. // hud.mode = MBProgressHUDModeAnnularDeterminate; // 圆形进度条
  73. // 隐藏时候从父控件中移除
  74. hud.removeFromSuperViewOnHide = YES;
  75. // 1秒之后再消失
  76. [hud hideAnimated:YES afterDelay:1];
  77. }
  78. /** 成功 */
  79. + (void)showSuccess:(NSString *)success {
  80. [self showSuccess:success toView:nil];
  81. }
  82. + (void)showSuccess:(NSString *)success toView:(UIView *)view
  83. {
  84. [self show:success icon:@"success.png" view:view];
  85. }
  86. /** 错误 */
  87. + (void)showError:(NSString *)error {
  88. [self showError:error toView:nil];
  89. }
  90. + (void)showError:(NSString *)error toView:(UIView *)view{
  91. [self show:error icon:@"error.png" view:view];
  92. }
  93. /** 隐藏 */
  94. + (void)hideHUD {
  95. [self hideHUDForView:nil];
  96. }
  97. + (void)hideHUDForView:(UIView *)view {
  98. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  99. // 隐藏时候从父控件中移除
  100. [self hideHUDForView:view animated:YES];
  101. }
  102. @end