MBProgressHUD的基本使用
和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的效果可以参考MBProgressHUD在gitHub上的DEMO,写得也很清楚明了。
先下载MBProgressHUD.h和.m文件,拖入工程。地址:MBProgressHUD
以下是代码:(先在.h文件里定义 MBProgressHUD *HUD;)
- //方式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:2];
- //只显示文字
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.labelText = @"Some message...";
- hud.margin = 10.f;
- hud.yOffset = 150.f;
- hud.removeFromSuperViewOnHide = YES;
- [hud hide:YES afterDelay:3];
- //方式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:3];
代理方法:
- #pragma mark -
- #pragma mark HUD的代理方法,关闭HUD时执行
- -(void)hudWasHidden:(MBProgressHUD *)hud
- {
- [hud removeFromSuperview];
- [hud release];
- hud = nil;
- }
二个task
- -(void) doTask{
- //你要进行的一些逻辑操作
- sleep(2);
- }
- -(void) myProgressTask{
- float progress = 0.0f;
- while (progress < 1.0f) {
- progress += 0.01f;
- HUD.progress = progress;
- usleep(50000);
- }
- }
MBProgressHUD的基本使用的更多相关文章
- MBProgressHud添加自定义动画
在使用自定义view时,若直接使用,如下 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud ...
- IOS MBProgressHUD的使用
一,简介 苹果的应用程序一般都会用一种优雅的,半透明的进度显示效果,不过这个API是不公开的,因此你要是用了,很可能被清除出AppStore.而 MBProgressHUD提供了一个替 ...
- iOS基于MBProgressHUD的二次封装,一行搞定,使用超简单
MBProgressHUD的使用,临时总结了几款最常用的使用场景: 1.提示消息 用法: [YJProgressHUD showMessage:@"显示文字,1s隐藏" inVie ...
- MBProgressHUD上传照片进度提示
第一步,控制器先来个属性 @property (strong, nonatomic) MBProgressHUD *HUD; 第二步,显示与隐藏的调用方法 - (void)hudTipWillShow ...
- MBProgressHUD+FastCall
+ (void)showHudTipStr:(NSString *)tipStr; + (void)showHudTipStr:(NSString *)tipStr{ ) { MBProgressHU ...
- MBProgressHUD框架的使用:https://github.com/jdg/MBProgressHUD
MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBP ...
- MBProgressHUD使用
//方式1.直接在View上show HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain]; HUD.delegat ...
- MBProgressHUD.h file not found
MBProgressHUD框架,怎么我导入MBProgressHUD+MJ.h会报错.(即MBProgressHUD+MJ根本不存在),我看其他人的视屏又可以导入 MBProgressHUD.h fi ...
- 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD
原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...
- MBProgressHUD 扩展加载动画
效果图: 设计给了一个组的图片,但是由于是透明的背景,会产生卡顿,其实只要两张图片就可以了 创建一个 MBProgressHUD 分类 增加方法 + (MB_INSTANCETYPE)myShowHU ...
随机推荐
- 线程间同步之 semaphore(信号量)
原文地址:http://www.cnblogs.com/yuqilin/archive/2011/10/16/2214429.html semaphore 可用于进程间同步也可用于同一个进程间的线程同 ...
- rails console --sandbox出现的安装错误解决方案
rails中可以用使用console命令行来测试运行rails应用程序,但是采用源码编译安装的话可能缺少readline动态库,导致ruby无法使用这个库此时如果调用rails console(rai ...
- B - I Hate It - hdu 1754
Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟 ...
- tomcat : Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException:
错误 严重: Error configuring application listener of class org.springframework.web.context.ContextLoader ...
- awk--动作(action)
摘要 在awk--简述中我们讲到awk是由pattern-action组合而成的,关于pattern我们已经awk--模式(pattern)在讲述,接下来就来看下awk的action. 动作是什么 我 ...
- svn解决方案汇总
http://blog.csdn.net/superch0054/article/details/38668017
- [Javascript] Refactoring: Polymorphic Functions
if-statements can add serious complexity and beg for refactoring. You can use polymorphic functions ...
- "蓝筹"如何使程序猿?
"蓝筹"这个词可能不是很多人知道这意味着什么.我会来普及知识.这是最重要的概念是指"越来越从长远来看更有价值"的含义.作为一个程序猿,我想你想使自己通过实际行动 ...
- Java 异常处理的误区和经验总结--转载
本文着重介绍了 Java 异常选择和使用中的一些误区,希望各位读者能够熟练掌握异常处理的一些注意点和原则,注意总结和归纳.只有处理好了异常,才能提升开发人员的基本素养,提高系统的健壮性,提升用户体验, ...
- Linux GRUB 2及修改默认启动项
The GRUB 2 boot loader makes sure that you can boot Linux. GRUB 2 is installed in the boot sector of ...