github链接地址

MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单、方便,并且可以对显示的内容进行自定义,功能很强大,很多项目中都有使用到。

MBProgressHUD is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.

Usage

The main guideline you need to follow when dealing with MBProgressHUD while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. The recommended way of using MBProgressHUD is therefore to set it up on the main thread and then spinning the task, that you want to perform, off onto a new thread.

程序在执行一个长时间任务的时候(例如网络请求),可以使用该类库在主窗口中添加一个提示框显示进度或者相关的提示信息。

  1. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  2. dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  3. // Do something...
  4. dispatch_async(dispatch_get_main_queue(), ^{
  5. [MBProgressHUD hideHUDForView:self.view animated:YES];
  6. });
  7. });

在这个类库中,提供了丰富的设置方法,可以构建出令人满意的提示框,在github下载这个项目就包括了一个demo,里面涵盖了所以基本的设置方法。

下面简单的记录一下。

//新建一个HUD添加到视图中

MBProgressHUD *HUD;

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];

// Regiser for HUD callbacks so we can remove it from the window at the right time设置代理
HUD.delegate = self;

// Show the HUD while the provided method executes in a new thread 显示HUD的同时执行其他的操作
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

//设置相关的文本提示信息

HUD.labelText = @"Loading";

HUD.detailsLabelText = @"updating data";

//设置HUD的颜色  Set the hud to display with a color

HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];

// Set determinate mode
HUD.mode = MBProgressHUDModeDeterminate;

//HUD的mode包括以下几种:

typedef enum {
/** Progress is shown using an UIActivityIndicatorView. This is the default. */  (默认是UIActivityIndicatorView样式)
MBProgressHUDModeIndeterminate,     
/**Progress is shown using a round, pie-chart like, progress view. */  (类似饼状图)
MBProgressHUDModeDeterminate,
/**Progress is shown using a ring-shaped progress view. */  (类似圆环)
MBProgressHUDModeAnnularDeterminate,
/**Shows a custom view */  (自定义)
MBProgressHUDModeCustomView,
/** Shows only labels */  (纯文本)
MBProgressHUDModeText
} MBProgressHUDMode;

当mode选择custom时,需要设置custom view

HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] ;

使用Blocks

[hud showAnimated:YES whileExecutingBlock:^{
[self myTask]; //hud显示过程中执行的其他操作
} completionBlock:^{
[hud removeFromSuperview];  
}];

// 设置HUD显示所在的视图背景暗淡

HUD.dimBackground = YES;

//设置HUD的进度

HUD.progress

//其他

- (void)show:(BOOL)animated;

- (void)hide:(BOOL)animated;

- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay;

iOS 第三方类库之MBProgressHUD的更多相关文章

  1. iOS第三方类库JSPatch(热更新)

    ---------------------------------------------------------------------------------------------------- ...

  2. iOS第三方类库汇总【持续更新】

    在我们平时开发中会经常使用一些第三方开发的开源类库.这样会有效地提高我们开发项目的效率,在这里我找了好几十个进行一个汇总,供大家参考使用,方便大家在需要的时候能容易找到. UI篇 awesome-io ...

  3. IOS 第三方库之-MBProgressHUD的使用详解

    转自作者: weidfyr  http://www.aiuxian.com/article/p-3121607.html 1,MBProgressHUD常用属性和用法Demo - (void)test ...

  4. iOS 常用第三方类库、完整APP示例

    一.第三方类库 1:基于响应式编程思想的oc地址:https://github.com/ReactiveCocoa/ReactiveCocoa2:hud提示框地址:https://github.com ...

  5. iOS开发常用的第三方类库

    在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使我们的开发变得更有效率:同时,也可以从它们的源代码中学习到很多有用的东西. Reachability 检测网络连接 用来检查网 ...

  6. 【转】iOS开发常用的第三方类库

    原文: http://blog.csdn.net/xiazailushang/article/details/9716043 在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使 ...

  7. iOS常用第三方类库及Xcode插件

    第三方类库(github地址): 1.AFNetworking 网络数据     https://github.com/AFNetworking/AFNetworking 2.SDWebImage 图 ...

  8. iOS 如何在一个已经存在多个project的workspace中引入cocoapods管理第三方类库

    一种新的第三方库管理工具:Carthage 如何使用Carthage管理iOS依赖库 Podfile Syntax Reference v1.1.0.rc.3 https://guides.cocoa ...

  9. IOS网络编程——第三方类库

    IOS网络编程——第三方类库 目录 概述 ASIHttpRequest AFNetworking 其他 概述 ASIHttpRequest AFNetworking 其他

随机推荐

  1. C#异步调用的应用实践浅谈

    C#异步调用的应用实践最经公司工作需要调用一个外部的webservice,同时要将传出的数据进行保存,以自己以前的习惯,就打算逐步操作,失败啊,完全没考虑过用户体验效果,在同事指点下,意识到使用C#异 ...

  2. [Xcode 实际操作]七、文件与数据-(22)使用OCR光学字符识别技术识别银行卡号码

    目录:[Swift]Xcode实际操作 本文将演示如何使用光学字符识别技术,识别信用卡上的卡号. OCR技术是光学字符识别的缩写(Optical Character Recognition), 是通过 ...

  3. 简单重载运算符in priority_queue By cellur925

    我们都知道priority_queue是大根堆. 一.变成小根堆 法一:把元素的相反数丢进堆中 法二 priority_queue<int,vector<int>,greater&l ...

  4. linux常用命令(ubuntu)

    编辑: vi [path] vim [path] :q 退出 :wq 保存退出 查看进程 ps ps -aux | grep mem 查看全部含 “mem”的进程 ps –aux  查看全部 在系统启 ...

  5. UWP 基本控件

    -------持续更新 updated 2017.11.8---------------------- 一:TextBlock 文本显示框 1. IsTextSelectionEnabled属性  值 ...

  6. 洛谷2758(字符串dp)

    题目传送 记得这是我初学dp时的一道题 虽说就像LCS一样搞一搞即可 但我还是写挂了qwq #include <cstdio> #include <cstring> #incl ...

  7. Java EE学习笔记(二)

    Spring中的Bean 1.Bean的配置: a).Bean的本质就是Java中的类,而Spring中的Bean其实就是对实体类的引用,来生产Java类对象,从而实现生产和管理Bean . b).S ...

  8. WPF学习04:2D绘图 使用Shape绘基本图形

    我们将使用Shape进行基本图形绘制. 例子 一个可移动的矩形方框: XAML代码: <Window x:Class="Shape.MainWindow" xmlns=&qu ...

  9. 《Python基础教程》 读书笔记 第九章 魔法方法、属性和迭代器(上)

    构造方法 在Python中创建一个构造方法很容易.只要把init方法的名字从简单的init修改为魔法版本__init__即可: >>> class FooBar: ...     d ...

  10. 洛谷 P1309 瑞士轮

    题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...