分类: IOS2012-10-30 11:19 12047人阅读 评论(2) 收藏 举报

和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的效果可以参考MBProgressHUD在gitHub上的DEMO,写得也很清楚明了。

先下载MBProgressHUD.h和.m文件,拖入工程。地址:MBProgressHUD

以下是代码:(先在.h文件里定义 MBProgressHUD *HUD;)

  1. //方式1.直接在View上show
  2. HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
  3. HUD.delegate = self;
  4. //常用的设置
  5. //小矩形的背景色
  6. HUD.color = [UIColor clearColor];//这儿表示无背景
  7. //显示的文字
  8. HUD.labelText = @"Test";
  9. //细节文字
  10. HUD.detailsLabelText = @"Test detail";
  11. //是否有庶罩
  12. HUD.dimBackground = YES;
  13. [HUD hide:YES afterDelay:2];
  14. //只显示文字
  15. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  16. hud.mode = MBProgressHUDModeText;
  17. hud.labelText = @"Some message...";
  18. hud.margin = 10.f;
  19. hud.yOffset = 150.f;
  20. hud.removeFromSuperViewOnHide = YES;
  21. [hud hide:YES afterDelay:3];
  22. //方式2.initWithView
  23. //use block
  24. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  25. [self.view addSubview:HUD];
  26. HUD.labelText = @"Test";
  27. [HUD showAnimated:YES whileExecutingBlock:^{
  28. NSLog(@"%@",@"do somethings....");
  29. [self doTask];
  30. } completionBlock:^{
  31. [HUD removeFromSuperview];
  32. [HUD release];
  33. }];
  34. //圆形进度条
  35. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  36. [self.view addSubview:HUD];
  37. HUD.mode = MBProgressHUDModeAnnularDeterminate;
  38. HUD.delegate = self;
  39. HUD.labelText = @"Loading";
  40. [HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
  41. //自定义view
  42. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  43. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
  44. // Set custom view mode
  45. HUD.mode = MBProgressHUDModeCustomView;
  46. HUD.delegate = self;
  47. HUD.labelText = @"Completed";
  48. [HUD show:YES];
  49. [HUD hide:YES afterDelay:3];

代理方法:

  1. #pragma mark -
  2. #pragma mark HUD的代理方法,关闭HUD时执行
  3. -(void)hudWasHidden:(MBProgressHUD *)hud
  4. {
  5. [hud removeFromSuperview];
  6. [hud release];
  7. hud = nil;
  8. }

二个task

  1. -(void) doTask{
  2. //你要进行的一些逻辑操作
  3. sleep(2);
  4. }
  5. -(void) myProgressTask{
  6. float progress = 0.0f;
  7. while (progress < 1.0f) {
  8. progress += 0.01f;
  9. HUD.progress = progress;
  10. usleep(50000);
  11. }
  12. }

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

  1. MBProgressHud添加自定义动画

    在使用自定义view时,若直接使用,如下 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud ...

  2. IOS MBProgressHUD的使用

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

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

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

  4. MBProgressHUD上传照片进度提示

    第一步,控制器先来个属性 @property (strong, nonatomic) MBProgressHUD *HUD; 第二步,显示与隐藏的调用方法 - (void)hudTipWillShow ...

  5. MBProgressHUD+FastCall

    + (void)showHudTipStr:(NSString *)tipStr; + (void)showHudTipStr:(NSString *)tipStr{ ) { MBProgressHU ...

  6. MBProgressHUD框架的使用:https://github.com/jdg/MBProgressHUD

    MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBP ...

  7. MBProgressHUD使用

    //方式1.直接在View上show HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain]; HUD.delegat ...

  8. MBProgressHUD.h file not found

    MBProgressHUD框架,怎么我导入MBProgressHUD+MJ.h会报错.(即MBProgressHUD+MJ根本不存在),我看其他人的视屏又可以导入 MBProgressHUD.h fi ...

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

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

  10. MBProgressHUD 扩展加载动画

    效果图: 设计给了一个组的图片,但是由于是透明的背景,会产生卡顿,其实只要两张图片就可以了 创建一个 MBProgressHUD 分类 增加方法 + (MB_INSTANCETYPE)myShowHU ...

随机推荐

  1. Delphi中文本文件的操作

    Delphi中文本文件的操作 相关知识内容: 在对文本文件进行任何处理之前,首先要打开此文本文件.声明变量:通过此变量可以来引用一个文本文件. 打开一个文件需要两步:首先是 AssignFile(), ...

  2. linux常用命令2

    1.top 最近自己最常用的是 top d -1(每秒刷新一次) 主要看Mem used使用内存:CPU idle 剩余CPU:CPMMAND进程:以及%CPU进程所占用CPU. 目前主要是系统出问题 ...

  3. Understanding the Android Life Cycle

    Problem Android apps do not have a “main” method; you need to learn how they get started and how the ...

  4. 设计模式学习--复合模式(Compound Pattern)

    设计模式学习--复合模式(Compound Pattern) 概述 ——————————————————————————————————————————————————— 2013年8月4日<H ...

  5. SWIFT国际资金清算系统

    SWIFT又称:“环球同业银行金融电讯协会”,是国际银行同业间的国际合作组织,成立于一九七三年,目前全球大多数国家大多数银行已使用SWIFT系统.SWIFT的使用,使银行的结算提供了安全.可靠.快捷. ...

  6. android中画文字的换行 办法(对于遇到canvas.drawText(String s )无法实现换行问题的解决)

    在使用canvas.drawText()绘制文字的时候,发现,如果需要绘制的文字较长,需要换行,通过在文字中加上“\n"或者”\r\n"都无法实现换行,如果非要使用canvas.d ...

  7. 持久化API(JPA)系列(三)实体Bean的开发技术-建立与数据库的连接

    在EJB 2.x中.EJB有3种类型的Bean.各自是会话Bean(Session Bean).消息驱动Bean(Message-Driven Bean)和实体Bean(Entity Bean). 随 ...

  8. C++标准库之 Lower_Bound, upper_Bound

    关于二分查找,这绝对是最简单却又最难的实现了,其各种版本号能够參见http://blog.csdn.net/xuqingict/article/details/17335833 在C++的标准库中,便 ...

  9. SVN经常使用命令说明

    SVN版本号:1.5 及更新版本号 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本号控制的 SVN是什么? SVN是开源的版本号控制系统. 比CVS很多其它 ...

  10. Java基础知识强化95:Calendar类之Calendar类的add()和set()方法

    1. Calendar的add()和set()方法: public void add(int field,int amount):根据给定的日历字段和对应的时间,来对当前的日历进行操作 public ...