关键操作:

 

效果如下:

 

ViewController.h

 #import <UIKit/UIKit.h>
#import "MBProgressHUD.h" @interface ViewController : UITableViewController<MBProgressHUDDelegate>
@property (strong, nonatomic) MBProgressHUD *hud;
@property (copy, nonatomic) NSArray *arrMode;
@property (copy, nonatomic) NSArray *arrModeName; @end

ViewController.m

 #import "ViewController.h"

 @interface ViewController ()
- (void)loadData;
- (void)layoutUI;
- (void)taskOfIndeterminate;
- (void)taskOfDeterminate;
- (void)taskOfDeterminateHorizontalBar;
- (void)taskOfAnnularDeterminate;
- (void)taskOfCustomView;
- (void)taskOfText;
- (void)showHUDByIndeterminate;
- (void)showHUDByDeterminate;
- (void)showHUDByDeterminateHorizontalBar;
- (void)showHUDByAnnularDeterminate;
- (void)showHUDByCustomView;
- (void)showHUDByText;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; [self loadData];
[self layoutUI];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)loadData {
_arrMode = @[ @"MBProgressHUDModeIndeterminate",
@"MBProgressHUDModeDeterminate",
@"MBProgressHUDModeDeterminateHorizontalBar",
@"MBProgressHUDModeAnnularDeterminate",
@"MBProgressHUDModeCustomView",
@"MBProgressHUDModeText" ]; _arrModeName = @[ @"UIActivityIndicatorView 来显示进度,这是默认值",
@"圆形饼图来显示进度",
@"水平进度条来显示进度",
@"圆环来显示进度",
@"自定义视图;例如通过这种方式,来显示一个正确或错误的提示图",
@"只显示文本" ];
} - (void)layoutUI {
self.navigationItem.title = @"MBProgressHUD 第三方库使用";
} #pragma mark - MBProgressHUD Additional Task
- (void)taskOfIndeterminate {
sleep(); //进程挂起3秒,这里仅仅是模拟,相当于执行了一些操作耗时3秒;sleep 和 usleep 都是进程挂起操作方法,他们的精准度不同,所以按需使用;对于一般秒级别操作,就使用 sleep 方法
} - (void)taskOfDeterminate {
CGFloat progressVal = 0.0f;
while (progressVal < 1.0) {
progressVal += 0.1;
_hud.progress = progressVal;
usleep(); //千分之一毫秒,即百万分之一秒;这里设置进程挂起0.5秒
}
} - (void)taskOfDeterminateHorizontalBar {
[self taskOfDeterminate];
} - (void)taskOfAnnularDeterminate {
[self taskOfDeterminate];
} - (void)taskOfCustomView {
[self taskOfIndeterminate];
} - (void)taskOfText {
[self taskOfIndeterminate];
} #pragma mark - MBProgressHUD
- (void)showHUDByIndeterminate {
UIColor *color = [UIColor cyanColor]; _hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.activityIndicatorColor = color; //设置指示器颜色;默认为白色 //label 和 detailsLabel 是公共部分,其他模式的展示效果一样可以用
_hud.labelText = @"加载中...";
_hud.labelFont = [UIFont systemFontOfSize:];
_hud.labelColor = color; //设置文本颜色;默认为白色
_hud.detailsLabelText = @"用户请稍候,耐心等待";
_hud.detailsLabelFont = [UIFont systemFontOfSize:];
_hud.detailsLabelColor = color; //设置详细文本颜色;默认为白色 //一些额外不常用的设置
_hud.minShowTime = 5.0f;
_hud.opacity = 0.5f;
_hud.animationType = MBProgressHUDAnimationZoomOut;
_hud.cornerRadius = 15.0f;
_hud.dimBackground = YES;
_hud.xOffset = 0.0f;
_hud.yOffset = 50.0f;
_hud.margin = 30.0f;
_hud.square = YES;
_hud.minSize = CGSizeMake(240.0f, 200.0f); //设置了 minSize 后,square 就失效了 //设置委托,以便调用hudWasHidden:方法
_hud.delegate = self;
[self.view addSubview:_hud]; //操作方式一:
// [_hud showWhileExecuting:@selector(taskOfIndeterminate)
// onTarget:self
// withObject:nil
// animated:YES]; //操作方式二:
[_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfIndeterminate];
} completionBlock:^{
NSLog(@"showHUDByIndeterminate 执行完成");
}];
} - (void)showHUDByDeterminate {
_hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.mode = MBProgressHUDModeDeterminate;
[self.view addSubview:_hud]; [_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfDeterminate];
} completionBlock:^{
NSLog(@"showHUDByDeterminate 执行完成");
}];
} - (void)showHUDByDeterminateHorizontalBar {
_hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
[self.view addSubview:_hud]; [_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfDeterminateHorizontalBar];
} completionBlock:^{
NSLog(@"showHUDByDeterminateHorizontalBar 执行完成");
}];
} - (void)showHUDByAnnularDeterminate {
_hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.mode = MBProgressHUDModeAnnularDeterminate;
[self.view addSubview:_hud]; [_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfAnnularDeterminate];
} completionBlock:^{
NSLog(@"showHUDByAnnularDeterminate 执行完成");
}];
} - (void)showHUDByCustomView {
_hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.mode = MBProgressHUDModeCustomView;
_hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"AlbumCellRedSelected"]];
[self.view addSubview:_hud]; [_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfCustomView];
} completionBlock:^{
NSLog(@"showHUDByCustomView 执行完成");
}]; } - (void)showHUDByText {
UIColor *color = [UIColor cyanColor]; _hud = [[MBProgressHUD alloc] initWithView:self.view];
_hud.mode = MBProgressHUDModeText;
_hud.labelText = @"加载中...";
_hud.labelFont = [UIFont systemFontOfSize:];
_hud.labelColor = color; //设置文本颜色;默认为白色
_hud.detailsLabelText = @"用户请稍候,耐心等待";
_hud.detailsLabelFont = [UIFont systemFontOfSize:];
_hud.detailsLabelColor = color; //设置详细文本颜色;默认为白色
[self.view addSubview:_hud]; [_hud showAnimated:YES
whileExecutingBlock:^{
[self taskOfText];
} completionBlock:^{
NSLog(@"showHUDByText 执行完成");
}];
} #pragma mark - MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud {
NSLog(@"隐藏后做一些操作");
} #pragma mark - TableView
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"展示模式列表";
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _arrMode.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
} NSInteger row = indexPath.row;
cell.textLabel.text = _arrMode[row];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.detailTextLabel.text = _arrModeName[row];
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case :
[self showHUDByIndeterminate];
break;
case :
[self showHUDByDeterminate];
break;
case :
[self showHUDByDeterminateHorizontalBar];
break;
case :
[self showHUDByAnnularDeterminate];
break;
case :
[self showHUDByCustomView];
break;
case :
[self showHUDByText];
break;
} NSLog(@"%ld", (long)indexPath.row);
} @end

AppDelegate.h

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController; @end

AppDelegate.m

 #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *viewController = [[ViewController alloc] init];
_navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
_window.rootViewController = _navigationController;
//[_window addSubview:_navigationController.view]; //当_window.rootViewController关联时,这一句可有可无
[_window makeKeyAndVisible];
return YES;
} - (void)applicationWillResignActive:(UIApplication *)application {
} - (void)applicationDidEnterBackground:(UIApplication *)application {
} - (void)applicationWillEnterForeground:(UIApplication *)application {
} - (void)applicationDidBecomeActive:(UIApplication *)application {
} - (void)applicationWillTerminate:(UIApplication *)application {
} @end

输出结果:

 -- ::30.788 MBProgressHUDDemo[:]
-- ::36.090 MBProgressHUDDemo[:] showHUDByIndeterminate 执行完成
-- ::36.091 MBProgressHUDDemo[:] 隐藏后做一些操作
-- ::37.378 MBProgressHUDDemo[:]
-- ::43.208 MBProgressHUDDemo[:] showHUDByDeterminate 执行完成
-- ::44.435 MBProgressHUDDemo[:]
-- ::50.278 MBProgressHUDDemo[:] showHUDByDeterminateHorizontalBar 执行完成
-- ::51.692 MBProgressHUDDemo[:]
-- ::57.529 MBProgressHUDDemo[:] showHUDByAnnularDeterminate 执行完成
-- ::58.473 MBProgressHUDDemo[:]
-- ::01.778 MBProgressHUDDemo[:] showHUDByCustomView 执行完成
-- ::02.790 MBProgressHUDDemo[:]
-- ::06.096 MBProgressHUDDemo[:] showHUDByText 执行完成

MBProgressHUD 第三方库使用的更多相关文章

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

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

  2. 常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...

  3. iOS,第三方库使用

    1.ASIHttpRequest网络请求库 2.MBProgressHUD指示层库 3.Toast+UIView提示库 4.SDWebImage图片缓存库 5.MGSwipeTableCell单元格侧 ...

  4. CocoaPods 添加第三方库报错

    1.终端报错:The dependency MBProgressHUD (~> 0.9.2) is not used in any concrete target.2.原因:CocoaPods升 ...

  5. 个人常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...

  6. 【转】个人常用iOS第三方库以及XCode插件介绍 -- 不错

    原文网址:http://adad184.com/2015/07/08/my-favorite-libraries-and-plugins/ 第三方库是现在的程序员离不开的东西 不光是APP开发 基本上 ...

  7. CocoaPods一个Objective-C第三方库的管理利器

    转:http://blog.csdn.net/totogo2010/article/details/8198694 介绍: 开发应用的时候第三方的库是不可缺少的,能提高开发的效率. 一些经常用到的库, ...

  8. Cocopods -第三方库的管理

    前言 什么是CocoaPods? CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods”的依赖库(这些类库必须是CocoaPods ...

  9. ios开发必备第三方库

    引言 作为iOS开发人员,在开发App的过程中怎么会不使用第三方库呢?相信没有App是不使用第三方库的! 网络库 网络库,这是开发必备,除非你的App玩单机.现在特别火也特别好用的网络库就数AFNet ...

随机推荐

  1. Spring的Assert工具类的用法

    简介 今天在看spring mvc源码时看到下面代码,感觉蛮有意思的,在这里记录下 Assert断言工具类,通常用于数据合法性检查,在JAVA编程中,通常会编写如下代码: if (name == nu ...

  2. 【Visual Studio】项目的引用显示黄色叹号

    情况一:个别引用的DLL显示黄色叹号. 通常是因为该DLL需要的.Net Framework版本与当前项目使用的版本不兼容.如该DLL需要的版本高于当前项目使用的版本.考虑修改项目的.Net Fram ...

  3. 【微信小程序】数据与界面UI不同步,不能直接操作Page.data

    问题:数据层与UI不同步 微信小程序也采用UI绑定数据源的形式,根据以前做WPF的经验,直觉上认为修改了数据层(Page.data)后,UI会自动更新,然而实验发现数据层修改后UI层未修改,导致数据层 ...

  4. OKR

    不得不佩服老外对概念的提炼能力.一套一套的. Mission Vision Strategic Objectives Key Results Tasks

  5. Android(我还是个菜鸟)——UI-开源框架ImageLoader的完美例子

    开源框架ImageLoader 可在文件里面找——Desktop.zip(原文件为jar格式) 使用这个框架的好处: 让图片能在异步加载更加流畅,可以显示大量图片,在拖动ListView的时候不会出现 ...

  6. Android——使用Toolbar + DrawerLayout快速实现高大上菜单侧滑(转)

    今天就来使用官方支持库来快速实现这类效果,需要使用到Toolbar和DrawerLayout,详细步骤如下:(如果你还不知道这两个Widget,先自己Google吧~) 1.首先需要添加appcomp ...

  7. 由于无法验证发布者 所以windows阻止此软件

    打开Internet Explorer---菜单栏点“工具”---Internet选项--安全---自定义级别---安全设置---“ActiveX控件和插件下”的第5个“下载未签名的ActiveX控件 ...

  8. Drupal 7 配置ckeditor和ckfinder编辑器实现图片上传--不用wysisyg

    注意: 1.这里的ckeditor编辑器是独立模块,不是那个wysiwyg模块. 2.这里的图片上传仅仅为文章内图片,非字段图片.   1.下载文件(1) http://drupal.org/proj ...

  9. 大数据处理-Bitmap

    MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)" Bit-map空间压缩和快速排序去 ...

  10. 解决EasyUi中的DataGrid删除一条记录后,被删除的数据仍处于被选中状态问题

    项目中遇到这么一个问题,在easyui的datagrid中,删除一条记录成功,重新加载datagrid后,去点编辑操作,仍可把之前删除掉的那条记录进行编辑操作,正常情况应该是,删除后再去点击“编辑”, ...