iOS 使用MBProgressHUD提示

導入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];
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容