// // MBProgressHUD+Extension.m // djlt // // Created by macmini04 on 16/1/18. // Copyright © 2016年 com.topsage.djlt. All rights reserved. // #import "MBProgressHUD+Extension.h" @implementation MBProgressHUD (Extension) + (instancetype)showLoadingAddedToView:(UIView *)view { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = @"加载中"; hud.label.textColor = [UIColor YHColorWithHex:0x333333]; hud.label.font = [UIFont boldSystemFontOfSize:17]; hud.bezelView.backgroundColor = [UIColor whiteColor]; hud.bezelView.layer.cornerRadius = 14; hud.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3f]; return hud; } + (instancetype)showTip:(NSString *)tip { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.mode = MBProgressHUDModeText; hud.label.text = tip; hud.label.numberOfLines=0; hud.label.textColor = [UIColor whiteColor]; hud.label.font = [UIFont boldSystemFontOfSize:17]; hud.bezelView.backgroundColor = [UIColor blackColor]; hud.bezelView.layer.cornerRadius = 14; hud.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f]; [hud hideAnimated:YES afterDelay:1.0f]; return hud; } /** 显示信息 */ + (MBProgressHUD *)showMessage:(NSString *)message { return [self showMessage:message toView:nil]; } + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view { if (view == nil) view = [[UIApplication sharedApplication].windows lastObject]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = message; hud.mode =MBProgressHUDModeText; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失 [hud hideAnimated:YES afterDelay:2]; return hud; } + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view { if (view == nil) view = [[UIApplication sharedApplication].windows lastObject]; // 快速显示一个提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.label.text = text; // 设置图片 hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]]; // 再设置模式 hud.mode = MBProgressHUDModeCustomView; // hud.mode = MBProgressHUDModeAnnularDeterminate; // 圆形进度条 // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失 [hud hideAnimated:YES afterDelay:1]; } /** 成功 */ + (void)showSuccess:(NSString *)success { [self showSuccess:success toView:nil]; } + (void)showSuccess:(NSString *)success toView:(UIView *)view { [self show:success icon:@"success.png" view:view]; } /** 错误 */ + (void)showError:(NSString *)error { [self showError:error toView:nil]; } + (void)showError:(NSString *)error toView:(UIView *)view{ [self show:error icon:@"error.png" view:view]; } /** 隐藏 */ + (void)hideHUD { [self hideHUDForView:nil]; } + (void)hideHUDForView:(UIView *)view { if (view == nil) view = [[UIApplication sharedApplication].windows lastObject]; // 隐藏时候从父控件中移除 [self hideHUDForView:view animated:YES]; } @end