導入MBProgressHUD版本是0.9幾的版本
創建Helper類繼承NSObject
Helper.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface Helper : NSObject
//顯示loading
+(void)showLoadingWithView:(UIView *)aView;
//影藏loading
+(void)hiddonLoadingWithView:(UIView *)aView;
//顯示提示框
+ (void)showMessageWithHud:(NSString*)message
addTo:(UIViewController*)controller
yOffset:(CGFloat)yoffset;
Helper.m
+(void)showLoadingWithView:(UIView *)aView{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:aView animated:YES];
hud.labelText = @"加載中…";
//hud.color = [UIColor redColor];
hud.labelFont = [UIFont systemFontOfSize:14.0f];
}
+(void)hiddonLoadingWithView:(UIView *)aView{
[MBProgressHUD hideAllHUDsForView:aView animated:YES];
}
//顯示提示框
+ (void)showMessageWithHud:(NSString*)message
addTo:(UIViewController*)controller
yOffset:(CGFloat)yoffset
{
MBProgressHUD* hud = nil;
if (controller.view) {
hud = [MBProgressHUD showHUDAddedTo:controller.view animated:YES];
}
hud.yOffset = yoffset;//默認傳0,想顯示在屏幕的位置自己調試
hud.mode = MBProgressHUDModeText;
hud.detailsLabelText = message;
hud.margin = 10.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:1];
}