iOS_第3方类库MBprogressHUD

1,将下载好的第3方类库MBprogressHUD源代码包增加到project(事实上就是一个.h和.m文件)

2,进入project的Build Phases,将源代码包里面的所有.m文件所有加入到project

3,加入第3方类库的主头文件"MBProgressHUD.h"


显示代码:

// 一開始载入就,显示提示条
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:webView animated:YES];
    // 加一层蒙版
    hud.dimBackground = YES;
    hud.labelText = @"页面载入中...";
隐藏代码:

// 一旦载入完成,就隐藏提示条
    [MBProgressHUD hideAllHUDsForView:webView animated:YES];

自己定义显示图片:

// 抽取的,仅供分类内部调用
+ (void) showMsg:(NSString *)msg imgName:(NSString *)imgName
{
    // 显示到主窗体中
    MBProgressHUD *hud =[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    
    // 显示模式,改成customView,即显示自己定义图片(mode设置,必须写在customView赋值之前)
    hud.mode = MBProgressHUDModeCustomView;
    
    
    int delay = 1;   
    if ([imgName isEqualToString:@"error.png"]) {
        // 错误时,提示3秒钟
        delay = 3;
    }
    
    imgName = [NSString stringWithFormat:@"MBProgressHUD.bundle/%@",imgName];
    // 设置要显示 的自己定义的图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imgName]];
    // 显示的文字,比方:载入失败...载入中...
    hud.labelText = msg;
    // 标志:必须为YES,才干够隐藏,  隐藏的时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 3秒后自己主动隐藏
    
    log(@"%d",delay);
    [hud hide:YES afterDelay:delay];
}
其它经常使用属性
  
// 提示框的背景色  
hud.color = [UIColor clearColor];//这儿表示无背景  
// 提示下文的小文字  
hud.detailsLabelText = @"detail";  
// 阴影遮罩效果  
hud.dimBackground = YES;  
// 1秒之后隐藏
[hud hide:YES afterDelay:1];  
//仅仅显示文字   
hud.mode = MBProgressHUDModeText;  
// 外边距 和 Y方向偏移
hud.margin = 0;  
hud.yOffset = 0;  
// 隐藏后从父控件中移除
hud.removeFromSuperViewOnHide = YES;  
//圆形进度条  
hud.mode = MBProgressHUDModeAnnularDeterminate;  




原文地址:https://www.cnblogs.com/lxjshuju/p/7017519.html