// // MBProgressHUD+DS.m // LN_School // // Created by apple on 2017/4/6. // Copyright © 2017年 Danson. All rights reserved. // #import "MBProgressHUD+DS.h" @implementation MBProgressHUD (DS) #pragma mark 显示错误信息 + (void)showError:(NSString *)error ToView:(UIView *)view { [self showCustomIcon:@"error.png" Title:error ToView:view]; } + (void)showSuccess:(NSString *)success ToView:(UIView *)view { [self showCustomIcon:@"success.png" Title:success ToView:view]; } #pragma mark 显示一些信息 + (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view { if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text= message; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // YES代表需要蒙版效果 hud.dimBackground = YES; return hud; } //加载视图 + (void)showLoadToView:(UIView *)view { [self showMessage:@"加载中..." ToView:view]; } /** * 进度条View */ + (MBProgressHUD *)showProgressToView:(UIView *)view ProgressModel:(MBProgressHUDMode)model Text:(NSString *)text{ if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.mode = model; hud.label.text = text; return hud; } //快速显示一条提示信息 + (void)showAutoMessage:(NSString *)message{ [self showAutoMessage:message ToView:nil]; } //自动消失提示,无图 + (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{ [self showMessage:message ToView:view RemainTime:2.1 Model:MBProgressHUDModeText]; } //自定义停留时间,有图 +(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{ [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate]; } //自定义停留时间,无图 +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{ [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText]; } +(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{ if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.detailsLabel.text = message; //模式 hud.mode = model; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // YES代表需要蒙版效果 hud.dimBackground = YES; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // X秒之后再消失 [hud hide:YES afterDelay:time]; } + (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view { if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = title; // 设置图片 if ([iconName isEqualToString:@"error.png"] || [iconName isEqualToString:@"success.png"]) { hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", iconName]]]; }else{ hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]]; } // 再设置模式 hud.mode = MBProgressHUDModeCustomView; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // 2秒之后再消失 [hud hide:YES afterDelay:2.1]; } + (void)hideHUDForView:(UIView *)view { if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; [self hideHUDForView:view animated:YES]; } + (void)hideHUD { [self hideHUDForView:nil]; } @end void ShowHUD() { [MBProgressHUD showLoadToView:nil]; } void RemoveHUD() { [MBProgressHUD hideHUD]; } void ShowMsg(NSString *str) { [MBProgressHUD showAutoMessage:str]; } void ShowErrorMsg(NSString *str) { [MBProgressHUD showError:str ToView:nil]; } void ShowSuccessMsg(NSString *str) { [MBProgressHUD showSuccess:str ToView:nil]; } void ShowMsgUnOpen() { [MBProgressHUD showAutoMessage:@"暂未开放,敬请期待"]; } void showMsgUnconnect() { [MBProgressHUD showAutoMessage:@"网络未连接"]; } void ShowMsgError() { [MBProgressHUD showError:@"操作失败" ToView:nil]; } void ShowMsgSuccess() { [MBProgressHUD showCustomIcon:@"question_success.png" Title:@"操作成功" ToView:nil]; //[MBProgressHUD showSuccess:@"操作成功" ToView:nil]; } void showMsgByAlert(UIViewController *vc,NSString *str) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]]; [vc presentViewController:alertFind animated:true completion:nil]; }