美文网首页
iOS 使用MBProgressHUD提示

iOS 使用MBProgressHUD提示

作者: ZIM东东 | 来源:发表于2017-05-24 14:20 被阅读1838次

    导入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];
    }
    

    相关文章

      网友评论

          本文标题:iOS 使用MBProgressHUD提示

          本文链接:https://www.haomeiwen.com/subject/gtonxxtx.html