Aucune description

MBProgressHUD+Extension.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.labelText = @"加载中";
  13. hud.labelFont = [UIFont boldSystemFontOfSize:17];
  14. hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3];
  15. return hud;
  16. }
  17. + (instancetype)showTip:(NSString *)tip {
  18. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  19. hud.mode = MBProgressHUDModeText;
  20. hud.labelText = tip;
  21. hud.labelFont = [UIFont boldSystemFontOfSize:17];
  22. hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3];
  23. [hud hide:YES afterDelay:0.75];
  24. return hud;
  25. }
  26. /** 显示信息 */
  27. + (MBProgressHUD *)showMessage:(NSString *)message {
  28. return [self showMessage:message toView:nil];
  29. }
  30. + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
  31. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  32. // 快速显示一个提示信息
  33. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  34. hud.labelText = message;
  35. hud.mode =MBProgressHUDModeText;
  36. // 隐藏时候从父控件中移除
  37. hud.removeFromSuperViewOnHide = YES;
  38. // 1秒之后再消失
  39. [hud hide:YES afterDelay:2];
  40. return hud;
  41. }
  42. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
  43. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  44. // 快速显示一个提示信息
  45. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  46. hud.labelText = text;
  47. // 设置图片
  48. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
  49. // 再设置模式
  50. hud.mode = MBProgressHUDModeCustomView;
  51. // hud.mode = MBProgressHUDModeAnnularDeterminate; // 圆形进度条
  52. // 隐藏时候从父控件中移除
  53. hud.removeFromSuperViewOnHide = YES;
  54. // 1秒之后再消失
  55. [hud hide:YES afterDelay:1];
  56. }
  57. /** 成功 */
  58. + (void)showSuccess:(NSString *)success {
  59. [self showSuccess:success toView:nil];
  60. }
  61. + (void)showSuccess:(NSString *)success toView:(UIView *)view
  62. {
  63. [self show:success icon:@"success.png" view:view];
  64. }
  65. /** 错误 */
  66. + (void)showError:(NSString *)error {
  67. [self showError:error toView:nil];
  68. }
  69. + (void)showError:(NSString *)error toView:(UIView *)view{
  70. [self show:error icon:@"error.png" view:view];
  71. }
  72. /** 隐藏 */
  73. + (void)hideHUD {
  74. [self hideHUDForView:nil];
  75. }
  76. + (void)hideHUDForView:(UIView *)view {
  77. if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  78. // 隐藏时候从父控件中移除
  79. [self hideHUDForView:view animated:YES];
  80. }
  81. @end