#import "MBProgressHUD.h" @interface MBProgressHUD (Add) + (void)showError:(NSString *)error toView:(UIView *)view; + (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view; @end #import "MBProgressHUD+Add.h" @implementation MBProgressHUD (Add) #pragma mark 顯示錯誤信息 + (void)showError:(NSString *)error toView:(UIView *)view{ // 快速顯示一個提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.labelText = error; // 設置圖片 hud.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"alert_failed_icon.png"]] autorelease]; // 再設置模式 hud.mode = MBProgressHUDModeCustomView; // 隱藏時候從父控件中移除 hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失 [hud hide:YES afterDelay:1]; } #pragma mark 顯示一些信息 + (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view { // 快速顯示一個提示信息 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; hud.labelText = message; // 隱藏時候從父控件中移除 hud.removeFromSuperViewOnHide = YES; // YES代表需要蒙版效果 hud.dimBackground = YES; return hud; } @end