下载地址: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. [ CodeVS冲杯之路 ] P2492

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/2492/ 在此先orz小胖子,教我怎么路径压缩链表,那么这样就可以在任意节点跳进链表啦(手动@LCF) 对于查询操作,直 ...

  2. Swift : missing argument label 'xxx' in call

    http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call up vote37down v ...

  3. Chubby lock service for distributed system

    Chubby lock service在分布式系统中的应用 Chubby lock service在分布式系统中提供粗粒度的锁服务, 以及可靠的存储. 相比高性能, 设计的重点在于高可靠性和高可用性. ...

  4. 定制一个支持中英文的简单LaTex模板

    平常写汇报文档什么的,word排版有时还是比较费劲,遂定制一个简单的LaTex模板,中文默认为宋体,英文为LaTex默认字体,支持彩色高亮展示,有目录书签,有页眉展示,大致如下: LaTex代码如下: ...

  5. python批量下载图片3

    import urllib.request import os def url_open(url): req = urllib.request.Request(url) req.add_header( ...

  6. libev 学习使用

    libev 简单的I/O库.  a high performance full featured event loop written in c libev 的大小也比 libevent 小得多并且自 ...

  7. poj 1269(两条直线交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13481   Accepted: 59 ...

  8. Android 开发实用方法大全

    1.格式化价格,这个经常在计算费用精度的时候用到 /** * 格式化价格 * * @param argStr 传入价格字符串 * @return */ public static String get ...

  9. 实例教程:1小时学会Python(转)

    1 序言 面向读者 本文适合有经验的程序员尽快进入Python2.x世界.特别地,如果你掌握Java和Javascript,不用1小时你就可以用Python快速流畅地写有用的Python程序. Pyt ...

  10. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...