iOS:MBProgressHUD的基本使用
下载地址: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的基本使用的更多相关文章
- ios MBProgressHUD 使用,及二次封装
MBProgressHUD是一个显示HUD窗口的第三方类库,用于在执行一些后台任务时,在程序中显示一个表示进度的loading视图和两个可选的文本提示的HUD窗口.MBProgressHUD 二次封装 ...
- IOS MBProgressHUD的使用
一,简介 苹果的应用程序一般都会用一种优雅的,半透明的进度显示效果,不过这个API是不公开的,因此你要是用了,很可能被清除出AppStore.而 MBProgressHUD提供了一个替 ...
- iOS MBProgressHUD 之带底板的加载提示
文章来自:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...
- wesome-android
awesome-android Introduction android libs from github System requirements Android Notice If the lib ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- iOS提示框,为什么你应该使用 MBProgressHUD?
这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...
- iOS 第三方类库之MBProgressHUD
github链接地址 MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单.方便,并且可以对显示的内容进行自定义,功能很强大, ...
- iOS基于MBProgressHUD的二次封装,一行搞定,使用超简单
MBProgressHUD的使用,临时总结了几款最常用的使用场景: 1.提示消息 用法: [YJProgressHUD showMessage:@"显示文字,1s隐藏" inVie ...
- 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD
原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...
- IOS中(类似于进度条哪种效果)MBProgressHUD的使用
1.显示HUD MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.labelText = ...
随机推荐
- 使用dd命令克隆整个系统
神奇的ghost的原理是什么呢?不就是数据复制吗?Linux下的dd命令不就是最强大的数据复制工具! 既然如此,我为什么要使用g4l这样复杂的工具呢?一条dd命令不就可以帮我实现任意 ...
- 【MT8382/8121】使用绝对路径编译模块会导致recourse_overlay无法应用的问题
之前为了方便mm模块编译,写了个脚本,实现了在任意模块其子目录下执行脚本即可编译的功能. 其实原理就是一层一层目录地往上寻找Android.mk文件,找到存放Android.mk目录后,就把该目录当作 ...
- 4.flume实战(一)
需求:从指定网络端口采集数据输出到控制台 使用flume的关键就是写配置文件 a)配置source b)配置channel c)配置sink d)把以上三个组件串起来 我们看一下官网给的配置文件 # ...
- java类型强转
知乎: 首先基本数据类型不是对象,强转改的是值,分为有损和无损,有损会丢失数据细节. 然后对象,只有继承关系的类才能强转,改变的只是引用,而且向上转型是安全的,把你转为人类是安全的,你还是你,只是现在 ...
- redis的持久化(RDB&AOF的区别)
RDB 是什么? 在指定的时间间隔内将内存中的数据集快照写入磁盘, 也就是行话讲的Snapshot快照,它恢复时是将快照文件直接读到内存里. Redis会单独创建(fork)一个子进程来进行持久化,会 ...
- 部署web应用到虚拟主机的三种方式
方式一: 在 [tomcat]/conf/server.xml 文件中的<Engine>标签下的<Host>标签内部, 添加一个 <Context ...
- CF 999B. Reversing Encryption【模拟/string reverse】
[链接]:CF [代码]: #include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F fir ...
- CF 612C. Replace To Make Regular Bracket Sequence【括号匹配】
[链接]:CF [题意]:给你一个只含有括号的字符串,你可以将一种类型的左括号改成另外一种类型,右括号改成另外一种右括号 问你最少修改多少次,才能使得这个字符串匹配,输出次数 [分析]: 本题用到了栈 ...
- CodeForces 669C
链接:http://codeforces.com/problemset/problem/669/C http://www.cnblogs.com/Ash-ly/p/5443155.html 题意: 给 ...
- HDU 3516 Tree Construction
区间$dp$,四边形优化. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...