【开源类库学习】MBProgressHUD(提示框)
新博客:
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(提示框)的更多相关文章
- 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD
原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- [原]发布一个jQuery提示框插件,Github开源附主站,jquery.tooltips.js
一个简单精致的jQuery带箭头提示框插件 插件写好快一年了,和一个 弹出框插件(点击查看) 一起写的,一直没有整理出来,昨天得功夫整理并放到了github上,源码和网站均可在线看或下载. CSS中的 ...
- Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)
Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...
- 精美舒适的对话消息提示框--第三方开源--SweetAlertDialog
SweetAlertDialog(sweet-alert-dialog)是一个套制作精美.动画效果出色生动的Android对话.消息提示框 SweetAlertDialog(sweet-alert-d ...
- iOS提示框,为什么你应该使用 MBProgressHUD?
这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...
- JS学习笔记 -- 定时器,提示框的应用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android应用开发学习之Toast消息提示框
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1. 创建一个Toast对象.可 ...
- 【JS学习笔记】第一个JS效果——鼠标提示框
分析效果实现原理--鼠标提示框 样式:div的display 事件:onmouseover,onmouseout 编写JS的流程 布局:HTML+CSS 属性:确定需要修改哪些属性 事件:确定用户做哪 ...
随机推荐
- 【BZOJ3680】吊打xxx [模拟退火]
吊打XXX Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description gty又虐了一场比赛,被虐的蒟蒻 ...
- bzoj 1045糖果传递 数学贪心
首先我们假设平均数为ave 那么对于第1个人,我们假设他给第N个人K个糖果,第2个人给1,第3个人给2,第n个人给第n-1个人 那么对于第1个人给完n,第2个人给完1,第一个人不会再改变糖果数了,所以 ...
- poj 2312 Battle City(优先队列+bfs)
题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...
- dj定时任务
参考:http://www.mknight.cn/post/13/ https://blog.csdn.net/sicofield/article/details/50937338 一.INSTALL ...
- algorithm ch7 QuickSort
快速排序是基于分治模式的排序,它将数组a[p,...,r]分成两个子数组a[p,...q-1],a[q+1,...,r],使得a[p,...,q-1]中每个元素都小于a[q],而且小于等于a[q+1, ...
- Python 本地线程
1. 本地线程,保证即使是多个线程,自己的值也是互相隔离. 2.普通对象演示 import threading import time class A(): pass a=A() def func(n ...
- 关于EINTR错误的理解【转】
转自:http://www.xuebuyuan.com/1470645.html 最近在工作中遇到了EINTR错误,感到比较困惑,几番研究之后,颇有心得和收获,特记录如下,便于以后查询,也给有同样困惑 ...
- HTTP===如何理解网关
首先举个例子: 假设你的名字叫小不点(很小),你住在一个大院子里,你的邻居有很多小伙伴,父母是你的网关.当你想跟院子里的某个小伙伴玩,只要你在院子里大喊一声他的名字,他听到了就会回应你,并且跑出来跟你 ...
- flask+gunicorn中文文件下载报错问题及解决
导言 问题源起与一个静态文件下载的接口: from flask import Flask, current_app app = Flask(__name__) @app.route('/file_na ...
- js中如何对时间进行设置
js中如何对时间进行设置 Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getF ...