MBProgressHUD是我们在项目中常用的一种请求数据时的提示控件。首先也是需要我们下载MBProgressHUD工具,在把它加在我们的工程当中,在项目中进行调用。下载地址:https://github.com/jdg/MBProgressHUD
用法一 :(最简单的用法,不需要其他的操作)
(1)在数据加载之前添加代码,
[MBProgressHUD showHUDAddedTo:self.view animated:YES];//开始加载数据提示
(2)在数据加载成功之后添加
[MBProgressHUD hideHUDForView:self.view animated:YES];//隐藏加载数据提示
用法二:
//初始化进度框,置于当前的View当中
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
//如果设置此属性则当前的view置于后台
HUD.dimBackground =YES;
//设置对话框文字
HUD.label.text= @"请稍等";
//显示对话框
[HUD showAnimated:YES whileExecutingBlock:^{
//对话框显示时需要执行的操作
sleep(3);
} completionBlock:^{
//操作执行完后取消对话框
[HUD removeFromSuperview];
// HUD = nil;
}];
用法三:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self showTips:@"提示语"];
}
- (void)showTips:(NSString*)tips
{
MBProgressHUD *pHud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:pHud];
// Set custom view mode
pHud.mode = MBProgressHUDModeCustomView;
pHud.removeFromSuperViewOnHide = YES;
pHud.detailsLabel.text = tips;
pHud.detailsLabel.font = [UIFont systemFontOfSize:17.0];
pHud.yOffset = -45;
pHud.color = [UIColor redColor];
[pHud showAnimated:YES];
[pHud hideAnimated:YES afterDelay:3.0f];
}