iOS 使用MBProgressHUD提示

2017-05-24  本文已影响1838人  ZIM东东

导入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];
}
上一篇下一篇

猜你喜欢

热点阅读