您的位置:首页 > 移动开发 > IOS开发

iOS_第3方类库MBprogressHUD

2015-04-01 15:43 141 查看
时间 2014-08-06 18:22:29 CSDN博客原文 http://blog.csdn.net/pre_eminent/article/details/38405007

1,将下载好的第3方类库MBprogressHUD源码包 加入到工程 (其实就是一个.h和.m文件)

2,进入工程的Build Phases,将源码包里面的所有.m文件全部添加到工程

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: