新博客:

http://www.liuchendi.com

MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBProgressHUD.m放到自己的项目就可以了。这里有一个小Demo可以参考一下。

头文件部分:

  1. #import <UIKit/UIKit.h>
  2. #import "MBProgressHUD.h"
  3.  
  4. @interface ViewController : UIViewController
  5. {
  6.  
  7. MBProgressHUD *HUD;
  8. }
  9.  
  10. - (IBAction)showTextDialog:(id)sender; //文本提示框,默认情况下
  11. - (IBAction)showProgressOne:(id)sender; //第一种加载提示框
  12. - (IBAction)showProgressTwo:(id)sender; //第二种加载提示框
  13. - (IBAction)showProgressThree:(id)sender; //第三种加载提示框
  14. - (IBAction)showCustomDialog:(id)sender; //自定义提示框,显示打钩效果
  15. - (IBAction)showAllTextDialog:(id)sender; //显示纯文本提示框
  16.  
  17. @end

实现文件部分

  1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4.  
  5. @end
  6.  
  7. @implementation ViewController
  8.  
  9. - (void)viewDidLoad
  10. {
  11. [super viewDidLoad];
  12. // Do any additional setup after loading the view, typically from a nib.
  13. }
  14.  
  15. - (void)didReceiveMemoryWarning
  16. {
  17. [super didReceiveMemoryWarning];
  18. // Dispose of any resources that can be recreated.
  19. }
  20.  
  21. - (IBAction)showTextDialog:(id)sender {
  22.  
  23. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  24. [self.view addSubview:HUD];
  25.  
  26. HUD.dimBackground = YES; //把当前的view置于后台
  27. HUD.labelText = @"请稍等";
  28.  
  29. //显示对话框
  30. [HUD showAnimated:YES whileExecutingBlock:^{
  31.  
  32. sleep();
  33. } completionBlock:^{
  34. }];
  35. }
  36.  
  37. - (IBAction)showProgressOne:(id)sender {
  38.  
  39. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  40. [self.view addSubview:HUD];
  41.  
  42. HUD.labelText = @"正在加载";
  43. HUD.mode = MBProgressHUDModeDeterminate;
  44. //HUD.mode = MBProgressHUDModeAnnularDeterminate;
  45. [HUD showAnimated:YES whileExecutingBlock:^{
  46.  
  47. float progress = 0.0f;
  48. while (progress < 1.0f) {
  49. progress += 0.01f;
  50. HUD.progress = progress;
  51. usleep();
  52. }
  53. } completionBlock:^{
  54. [HUD removeFromSuperview];
  55. [HUD release];
  56. HUD = nil;
  57.  
  58. }];
  59. }
  60.  
  61. - (IBAction)showProgressTwo:(id)sender {
  62.  
  63. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  64. [self.view addSubview:HUD];
  65.  
  66. HUD.labelText = @"正在加载";
  67. HUD.mode = HUD.mode = MBProgressHUDModeAnnularDeterminate;
  68. [HUD showAnimated:YES whileExecutingBlock:^{
  69.  
  70. float progress = 0.0f;
  71. while (progress < 1.0f) {
  72. progress += 0.01f;
  73. HUD.progress = progress;
  74. usleep();
  75. }
  76. } completionBlock:^{
  77. [HUD removeFromSuperview];
  78. [HUD release];
  79. HUD = nil;
  80.  
  81. }];
  82.  
  83. }
  84.  
  85. - (IBAction)showProgressThree:(id)sender {
  86.  
  87. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  88. [self.view addSubview:HUD];
  89.  
  90. HUD.labelText = @"正在加载";
  91. HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
  92. [HUD showAnimated:YES whileExecutingBlock:^{
  93.  
  94. float progress = 0.0f;
  95. while (progress < 1.0f) {
  96. progress += 0.01f;
  97. HUD.progress = progress;
  98. usleep();
  99. }
  100. } completionBlock:^{
  101. [HUD removeFromSuperview];
  102. [HUD release];
  103. HUD = nil;
  104.  
  105. }];
  106.  
  107. }
  108.  
  109. - (IBAction)showCustomDialog:(id)sender {
  110.  
  111. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  112. [self.view addSubview:HUD];
  113.  
  114. HUD.labelText = @"操作成功";
  115. HUD.mode = MBProgressHUDModeCustomView;
  116. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease];
  117. [HUD showAnimated:YES whileExecutingBlock:^{
  118. sleep();
  119. } completionBlock:^{
  120. [HUD removeFromSuperview];
  121. [HUD release];
  122. HUD = nil;
  123. }];
  124. }
  125.  
  126. - (IBAction)showAllTextDialog:(id)sender {
  127.  
  128. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  129. [self.view addSubview:HUD];
  130.  
  131. HUD.labelText = @"操作成功";
  132. HUD.mode = MBProgressHUDModeText;
  133. HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease];
  134. [HUD showAnimated:YES whileExecutingBlock:^{
  135. sleep();
  136. } completionBlock:^{
  137. [HUD removeFromSuperview];
  138. [HUD release];
  139. HUD = nil;
  140. }];
  141.  
  142. }
  143.  
  144. - (void)dealloc {
  145.  
  146. [super dealloc];
  147. }
  148. @end

实现效果如图所示:

1、默认效果,也就是MBProgressHUDModeIndeterminate

2、第一种加载提示框,MBProgressHUDModeDeterminate

3、第二种加载提示MBProgressHUDModeAnnularDeterminate

4、第三种加载提示框,MBProgressHUDModeDeterminateHorizontalBar

5、自定义提示框 ,可以带图片的MBProgressHUDModeCustomView

6.纯文本提示框

如果有什么问题,欢迎通过微博交流 @Linux_小木头

【开源类库学习】MBProgressHUD(提示框)的更多相关文章

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

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

  2. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  3. [原]发布一个jQuery提示框插件,Github开源附主站,jquery.tooltips.js

    一个简单精致的jQuery带箭头提示框插件 插件写好快一年了,和一个 弹出框插件(点击查看) 一起写的,一直没有整理出来,昨天得功夫整理并放到了github上,源码和网站均可在线看或下载. CSS中的 ...

  4. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  5. 精美舒适的对话消息提示框--第三方开源--SweetAlertDialog

    SweetAlertDialog(sweet-alert-dialog)是一个套制作精美.动画效果出色生动的Android对话.消息提示框 SweetAlertDialog(sweet-alert-d ...

  6. iOS提示框,为什么你应该使用 MBProgressHUD?

    这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...

  7. JS学习笔记 -- 定时器,提示框的应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Android应用开发学习之Toast消息提示框

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1.  创建一个Toast对象.可 ...

  9. 【JS学习笔记】第一个JS效果——鼠标提示框

    分析效果实现原理--鼠标提示框 样式:div的display 事件:onmouseover,onmouseout 编写JS的流程 布局:HTML+CSS 属性:确定需要修改哪些属性 事件:确定用户做哪 ...

随机推荐

  1. 【BZOJ3680】吊打xxx [模拟退火]

    吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description gty又虐了一场比赛,被虐的蒟蒻 ...

  2. bzoj 1045糖果传递 数学贪心

    首先我们假设平均数为ave 那么对于第1个人,我们假设他给第N个人K个糖果,第2个人给1,第3个人给2,第n个人给第n-1个人 那么对于第1个人给完n,第2个人给完1,第一个人不会再改变糖果数了,所以 ...

  3. poj 2312 Battle City(优先队列+bfs)

    题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...

  4. dj定时任务

    参考:http://www.mknight.cn/post/13/ https://blog.csdn.net/sicofield/article/details/50937338 一.INSTALL ...

  5. algorithm ch7 QuickSort

    快速排序是基于分治模式的排序,它将数组a[p,...,r]分成两个子数组a[p,...q-1],a[q+1,...,r],使得a[p,...,q-1]中每个元素都小于a[q],而且小于等于a[q+1, ...

  6. Python 本地线程

    1. 本地线程,保证即使是多个线程,自己的值也是互相隔离. 2.普通对象演示 import threading import time class A(): pass a=A() def func(n ...

  7. 关于EINTR错误的理解【转】

    转自:http://www.xuebuyuan.com/1470645.html 最近在工作中遇到了EINTR错误,感到比较困惑,几番研究之后,颇有心得和收获,特记录如下,便于以后查询,也给有同样困惑 ...

  8. HTTP===如何理解网关

    首先举个例子: 假设你的名字叫小不点(很小),你住在一个大院子里,你的邻居有很多小伙伴,父母是你的网关.当你想跟院子里的某个小伙伴玩,只要你在院子里大喊一声他的名字,他听到了就会回应你,并且跑出来跟你 ...

  9. flask+gunicorn中文文件下载报错问题及解决

    导言 问题源起与一个静态文件下载的接口: from flask import Flask, current_app app = Flask(__name__) @app.route('/file_na ...

  10. js中如何对时间进行设置

    js中如何对时间进行设置 Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getF ...