分类: 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. cf590B Chip 'n Dale Rescue Rangers

    B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabytes inpu ...

  2. struct 结构

    //原始套接字学习笔记之代码结构 /* *host端程序结构 */ #include <> #define .. //主函数 int main() { //建立发送线程 pthread_t ...

  3. 用java具体代码实现分数(即有理数)四则运算

    用java具体代码实现分数(即有理数)四则运算 1,背景 Java老师布置了一个关于有理数运算的题目,因为参考书上有基本代码,所以自己主要是对书上代码做了一点优化,使其用户交互性更加友好以及代码封装性 ...

  4. android Json解析详解

    JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语 言的支持),从而可以在不同平台间进行数 ...

  5. Apache http强制转为https页面访问(转)

    1 在httpd.conf文件里使下面模块生效 LoadModule rewrite_module modules/mod_rewrite.so   2 httpd.conf配置文件或者是在httpd ...

  6. 开源消息中间件DotNetMQ

    由于这个开源项目对我这种中间件菜鸟很有帮助,因此,我将官方的说明文档翻译如下: Introduction In this article, I will introduce a new and ind ...

  7. automatically select architectures

    各位在用XCode 5.x 打开用XCode 4.x 创建的项目时候.会遇到编译器警告automatically select architectures. 1. This is because th ...

  8. NYOJ 10 skiing动态规划心得

    这道题目,拿到手中,首先想到的是搜索,但是,后来想了想搜索不知道从哪搜起,就看了一下分类,一看属于动态规划类的,因为以前没有接触过动态规划,所以在网上搜了一下动态规划的思想,看过之后也有想到将它们到周 ...

  9. 《fullPage.js》创建全屏滚动的网站

    插件介绍 fullPage.js是一个简单易用的插件,创建全屏滚动的网站(也被称为单页网站).它允许全屏滚动创建网站,以及添加内部滑块. 浏览器兼容性 主要功能 支持鼠标滚动 支持前进后退和键盘控制 ...

  10. string与stringbuilder的区别

    1.分析string与stringbuilder的区别,我们先来看下面一段代码 首先我们使用string进行字符串的拼接 class Program { static void Main(string ...