// // 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.labelText = @"加载中"; hud.labelFont = [UIFont boldSystemFontOfSize:17]; hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3]; return hud; } + (instancetype)showTip:(NSString *)tip { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES]; hud.mode = MBProgressHUDModeText; hud.labelText = tip; hud.labelFont = [UIFont boldSystemFontOfSize:17]; hud.backgroundColor = [UIColor KXColorWithHex:0x000000 alpha:0.3]; [hud hide:YES afterDelay:0.75]; 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.labelText = message; hud.mode =MBProgressHUDModeText; // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失 [hud hide: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.labelText = text; // 设置图片 hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]]; // 再设置模式 hud.mode = MBProgressHUDModeCustomView; // hud.mode = MBProgressHUDModeAnnularDeterminate; // 圆形进度条 // 隐藏时候从父控件中移除 hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失 [hud hide: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