#import "MBProgressHUD+MJ.h" @implementation MBProgressHUD (MJ) #pragma mark 显示信息 +(void)showPop:(NSString *)text { [self showError:text withView:nil]; } +(void)rkShowImgSuc:(NSString *)text { [self show:text icon:@"提示-勾" view:nil]; } + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view { //[[UIApplication sharedApplication].windows lastObject]; if (view == nil) view = [[UIApplication sharedApplication].delegate window]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = text; // 设置图片 //hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]]; hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:icon]]; // 再设置模式 hud.mode = MBProgressHUDModeCustomView; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; hud.contentColor = [UIColor whiteColor]; hud.bezelView.backgroundColor = [UIColor blackColor]; hud.bezelView.alpha = 1; // 1秒之后再消失 [hud hideAnimated:YES afterDelay:1.3]; } #pragma mark 显示错误信息 + (void)showError:(NSString *)error toView:(UIView *)view{ [self show:error icon:@"error.png" view:view]; } + (void)showSuccess:(NSString *)success toView:(UIView *)view { [self show:success icon:@"success.png" view:view]; } #pragma mark 显示一些信息 + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view { if (view == nil) view = [[UIApplication sharedApplication].delegate window]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = message; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; hud.contentColor = [UIColor whiteColor]; hud.bezelView.backgroundColor = [UIColor blackColor]; return hud; } + (void)showSuccess:(NSString *)success { [self showSuccess:success toView:[[UIApplication sharedApplication].delegate window]]; } + (void)showError:(NSString *)error { //[self showError:error toView:[UIApplication sharedApplication].keyWindow]; [self showError:error withView:nil]; } + (void)showError:(NSString *)error withView:(UIView *)view{ if (view == nil) view = [[UIApplication sharedApplication].delegate window]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = error; hud.label.font = [UIFont systemFontOfSize:13]; hud.label.numberOfLines = 0; hud.contentColor = [UIColor whiteColor]; hud.bezelView.backgroundColor = [UIColor blackColor]; hud.bezelView.alpha = 1; // 再设置模式 hud.mode = MBProgressHUDModeCustomView; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; [hud hideAnimated:YES afterDelay:1]; } + (MBProgressHUD *)showMessage:(NSString *)message { [self hideHUD]; return [self showMessage:message toView:[[UIApplication sharedApplication].delegate window]]; } + (void)hideHUDForView:(UIView *)view { // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self hideHUDForView:view animated:YES]; // }); } + (void)hideHUD { [self hideHUDForView:[[UIApplication sharedApplication].delegate window]]; } @end