新博客:

http://www.liuchendi.com

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

头文件部分:

#import <UIKit/UIKit.h>
#import "MBProgressHUD.h" @interface ViewController : UIViewController
{ MBProgressHUD *HUD;
} - (IBAction)showTextDialog:(id)sender; //文本提示框,默认情况下
- (IBAction)showProgressOne:(id)sender; //第一种加载提示框
- (IBAction)showProgressTwo:(id)sender; //第二种加载提示框
- (IBAction)showProgressThree:(id)sender; //第三种加载提示框
- (IBAction)showCustomDialog:(id)sender; //自定义提示框,显示打钩效果
- (IBAction)showAllTextDialog:(id)sender; //显示纯文本提示框 @end

实现文件部分

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)showTextDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.dimBackground = YES; //把当前的view置于后台
HUD.labelText = @"请稍等"; //显示对话框
[HUD showAnimated:YES whileExecutingBlock:^{ sleep();
} completionBlock:^{
}];
} - (IBAction)showProgressOne:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.labelText = @"正在加载";
HUD.mode = MBProgressHUDModeDeterminate;
//HUD.mode = MBProgressHUDModeAnnularDeterminate;
[HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep();
}
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
HUD = nil; }];
} - (IBAction)showProgressTwo:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.labelText = @"正在加载";
HUD.mode = HUD.mode = MBProgressHUDModeAnnularDeterminate;
[HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep();
}
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
HUD = nil; }]; } - (IBAction)showProgressThree:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.labelText = @"正在加载";
HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
[HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep();
}
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
HUD = nil; }]; } - (IBAction)showCustomDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.labelText = @"操作成功";
HUD.mode = MBProgressHUDModeCustomView;
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease];
[HUD showAnimated:YES whileExecutingBlock:^{
sleep();
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}];
} - (IBAction)showAllTextDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD]; HUD.labelText = @"操作成功";
HUD.mode = MBProgressHUDModeText;
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease];
[HUD showAnimated:YES whileExecutingBlock:^{
sleep();
} completionBlock:^{
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}]; } - (void)dealloc { [super dealloc];
}
@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. 【BZOJ2286】【SDOI2011】消耗战 [虚树][树形DP]

    消耗战 Time Limit: 20 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 在一场战争中,战场由n个岛屿和n-1 ...

  2. TensorFlow_曲线拟合

    # coding:utf-8 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt import os ...

  3. 【mysql】索引与排序、重复索引、冗余索引

    索引与排序 排序可能发生2种情况: 1: 对于覆盖索引,直接在索引上查询时,就是有顺序的, using index 2: 先取出数据,形成临时表做filesort(文件排序,但文件可能在磁盘上,也可能 ...

  4. LeetCode 192:Reverse Bits

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  5. CentOS RabbitMQ安装

    1. 安装erlang,参考另外一篇文章: http://www.cnblogs.com/wanpengcoder/p/5287302.html 2. 安装libxslt和: yum install ...

  6. letsencrypt的证书转换上传到360网站防护方法

    命令:openssl 首先letsencrypt生成的证书在 letsencrypt/live/xxx.com/ 下,需要使用cert.pem和privkey.pem文件. 生成crt文件: open ...

  7. Linux下f命令配置

    一.工具 f 的配置 使用 ========== ========== ========== ========== ========== ==========  ==== 一.配置方法: 首先在lin ...

  8. python 复习 4-1 函数、参数、返回值、递归

    函数 完成特定功能的一个语句组,这个语句组可以作为一个单位使用,并且给它组语句取一个名子,即函数名 可以通过函数名在程序不同地方多次执行,即函数调用 预定义函数(可以直接使用) 自定义函数(自编写的) ...

  9. Java常见知识点(一)

    1.+不仅可作为加法运算符使用,还可作为字符串连接运算符使用.   2.a = b = c = 7;//虽然java支持这种一次为多个变量赋值的写法,但这种写法导致程序的可读性降低,因此不推荐这样写. ...

  10. tkinter之事件绑定