下载地址:https://github.com/jdg/MBProgressHUD/

//方式1.直接在View上show
HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
HUD.delegate = self; //常用的设置
//小矩形的背景色
HUD.color = [UIColor clearColor];//这儿表示无背景
//显示的文字
HUD.labelText = @"Test";
//细节文字
HUD.detailsLabelText = @"Test detail";
//是否有庶罩
HUD.dimBackground = YES;
[HUD hide:YES afterDelay:]; //只显示文字
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"Some message...";
hud.margin = .f;
hud.yOffset = .f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:]; //方式2.initWithView
//use block
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.labelText = @"Test";
[HUD showAnimated:YES whileExecutingBlock:^{
NSLog(@"%@",@"do somethings....");
[self doTask];
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
}]; //圆形进度条
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.mode = MBProgressHUDModeAnnularDeterminate;
HUD.delegate = self;
HUD.labelText = @"Loading";
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES]; //自定义view
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = @"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:];

代理方法:

#pragma mark -
#pragma mark HUD的代理方法,关闭HUD时执行
-(void)hudWasHidden:(MBProgressHUD *)hud
{
[hud removeFromSuperview];
[hud release];
hud = nil;
}

二个task

 -(void) doTask{
//你要进行的一些逻辑操作
sleep();
} -(void) myProgressTask{
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep();
} }

注意: 其实,第三方库都是开源的,我们可以在其基础上添加另外自己需要的功能,如果觉得上面显示文字代码太不好用,可以添加一个分类,对它设置文字的方法再次封装如下所示:

添加一个分类:MBProgressHUD+XYQ

MBProgressHUD+XYQ.h文件:

#import "MBProgressHUD"

@interface MBProgressHUD (XYQ)
+ (void)showSuccess:(NSString *)success toView:(UIView *)view;
+ (void)showError:(NSString *)error toView:(UIView *)view; + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view; + (void)showSuccess:(NSString *)success;
+ (void)showError:(NSString *)error; + (MBProgressHUD *)showMessage:(NSString *)message; + (void)hideHUDForView:(UIView *)view;
+ (void)hideHUD; @end

MBProgressHUD+XYQ.m文件:

#import "MBProgressHUD+XYQ.h"

@implementation MBProgressHUD (XYQ)
#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.labelText = text;
// 设置图片
hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
// 再设置模式
hud.mode = MBProgressHUDModeCustomView; // 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES; // 1秒之后再消失
[hud hide:YES afterDelay:1.2];
} #pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view{
[self show:error icon:@"error.png" view:view];
} + (void)showSuccess:(NSString *)success toView:(UIView *)view
{
[self show:success icon:@"success.png" view:view];
} #pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.labelText = message;
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
// YES代表需要蒙版效果
hud.dimBackground = YES;
return hud;
} + (void)showSuccess:(NSString *)success
{
[self showSuccess:success toView:nil];
} + (void)showError:(NSString *)error
{
[self showError:error toView:nil];
} + (MBProgressHUD *)showMessage:(NSString *)message
{
return [self showMessage:message toView:nil];
} + (void)hideHUDForView:(UIView *)view
{
[self hideHUDForView:view animated:YES];
} + (void)hideHUD
{
[self hideHUDForView:nil];
}
@end

更详细的讲解请看该链接:http://blog.csdn.net/ryantang03/article/details/7877120

iOS:MBProgressHUD的基本使用的更多相关文章

  1. ios MBProgressHUD 使用,及二次封装

    MBProgressHUD是一个显示HUD窗口的第三方类库,用于在执行一些后台任务时,在程序中显示一个表示进度的loading视图和两个可选的文本提示的HUD窗口.MBProgressHUD 二次封装 ...

  2. IOS MBProgressHUD的使用

    一,简介         苹果的应用程序一般都会用一种优雅的,半透明的进度显示效果,不过这个API是不公开的,因此你要是用了,很可能被清除出AppStore.而 MBProgressHUD提供了一个替 ...

  3. iOS MBProgressHUD 之带底板的加载提示

    文章来自:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...

  4. wesome-android

    awesome-android Introduction android libs from github System requirements Android Notice If the lib ...

  5. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  6. iOS提示框,为什么你应该使用 MBProgressHUD?

    这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...

  7. iOS 第三方类库之MBProgressHUD

    github链接地址 MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单.方便,并且可以对显示的内容进行自定义,功能很强大, ...

  8. iOS基于MBProgressHUD的二次封装,一行搞定,使用超简单

    MBProgressHUD的使用,临时总结了几款最常用的使用场景: 1.提示消息 用法: [YJProgressHUD showMessage:@"显示文字,1s隐藏" inVie ...

  9. 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD

    原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...

  10. IOS中(类似于进度条哪种效果)MBProgressHUD的使用

    1.显示HUD MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.labelText = ...

随机推荐

  1. 关于Javascript 闭包的理解

    一.什么是闭包? 官方”的解释是:闭包是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.相信很少有人能直接看懂这句话,因为他描述的太学术.其实这句话 ...

  2. 使用dd命令克隆整个系统

    神奇的ghost的原理是什么呢?不就是数据复制吗?Linux下的dd命令不就是最强大的数据复制工具!          既然如此,我为什么要使用g4l这样复杂的工具呢?一条dd命令不就可以帮我实现任意 ...

  3. 使用SpringMVC解决Ajax跨域问题

    package com.mengyao.system.filter; import java.io.IOException; import javax.servlet.FilterChain; imp ...

  4. python-列表 字典 集合 元祖 字符串的相关总结练习

    1.执行python脚本的两种方式指定解释器执行在交互器中执行 2.简述位.字节的关系:ASCII1个二进制位是计算机里的最小表示单元1个字节是计算机里最小的储存单元二进制位=8bits(位)8bit ...

  5. linux基础之nginx和nfs服务

      第一部分: 一.nginx服务安装nginx包(源码安装)1.先cd /etc/yum.repos.d目录下2.yum install epel-release -y(安装扩展包)3.yum in ...

  6. Oracle基础 11 约束 constraints

    --主.外键约束 create table t(  id int primary key); create table t1(  id int references t(id)); 或者create ...

  7. 【bzoj3924&&luogu3345】幻想乡战略游戏

    这题可以用线段树做,不过正解恐怕是动态点分治?(点分树) 简单介绍下动态点分治的概念:在点分治的过程中,一般我们面对的问题都是静态的.如果涉及到修改这类的操作,我们就希望找到我们是如何处理到当前的修改 ...

  8. 【 VSFTPD 】ftp 客户端问题

    网络环境: 两个独立的内网环境,前端都有路由和防火墙的管控.要在这两个独立的内网使用ftp通过互联网进行通信. 首先,ftp server 服务端口默认修改为:2100 数据端口修改为:21000 将 ...

  9. html的表格

    表格元素及相关样式 1.<table>标签:声明一个表格 2.<tr>标签:定义表格中的一行 3.<td>和<th>标签:定义一行中的一个单元格,td代 ...

  10. CentOS7下,安装网卡驱动,命令行手动连接WIFI指导

    买了一个无线网卡,型号为TL-WN823N,谁知道在CentOS下没有驱动 于是开始了无线上网的漫漫征途 经历了无数个坑啊,解决了一个又一个的问题啊 到最后ping通的时候成就感简直爆棚 文章结构简介 ...