高级: http://www.jianshu.com/p/485b8d75ccd4

//只有小菊花

- (void)indeterminateExample {

// Show the HUD on the root view (self.view is a scrollable table view and thus not suitable,

// as the HUD would move with the content as we scroll).

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Fire off an asynchronous task, giving UIKit the opportunity to redraw wit the HUD added to the

// view hierarchy.

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background

[self doSomeWork];

// IMPORTANT - Dispatch back to the main thread. Always access UI

// classes (including MBProgressHUD) on the main thread.

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//小菊花+文字

- (void)labelExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the label text.

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

// You can also adjust other label properties if needed.

// hud.label.font = [UIFont italicSystemFontOfSize:16.f];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[self doSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//小菊花+文字+detailsLabel

- (void)detailsLabelExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the label text.

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

// Set the details label text. Let's make it multiline this time.

hud.detailsLabel.text = NSLocalizedString(@"Parsing data\n(1/1)", @"HUD title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[self doSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

- (void)windowExample {

// Covers the entire screen. Similar to using the root view controller view.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.windowanimated:YES];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[self doSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//圆环进度条+文字

- (void)determinateExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the determinate mode to show task progress.

hud.mode = MBProgressHUDModeDeterminate;

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//圆环进度条+文字+ 取消按钮

- (void)determinateNSProgressExample {

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];

// Set the determinate mode to show task progress.

hud.mode = MBProgressHUDModeDeterminate;

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

// Set up NSProgress

NSProgress *progressObject = [NSProgress progressWithTotalUnitCount:100];

hud.progressObject = progressObject;

// Configure a cancel button.

[hud.button setTitle:NSLocalizedString(@"Cancel", @"HUD cancel button title") forState:UIControlStateNormal];

[hud.button addTarget:progressObject action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithProgressObject:progressObject];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//圆环进度条+文字

- (void)annularDeterminateExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the annular determinate mode to show task progress.

hud.mode = MBProgressHUDModeAnnularDeterminate;

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//直线进度条+文字

- (void)barDeterminateExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the bar determinate mode to show task progress.

hud.mode = MBProgressHUDModeDeterminateHorizontalBar;

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

#pragma mark --自定义视图

//自定义视图

- (void)customViewExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the custom view mode to show any view.

hud.mode = MBProgressHUDModeCustomView;

// Set an image view with a checkmark.

//default

//    UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

//mxs

//UIImage *image = [[UIImage imageNamed:@"下拉刷新一80x80"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];//success  下拉刷新一80x80密码登录lgo

UIImage *image = [UIImage imageNamed:@"下拉刷新一80x80"];//success  下拉刷新一80x80 密码登录lgo

UIImageView *imgV = [[UIImageView alloc] initWithImage:image];

[imgV.layer addAnimation:[self makeRotation] forKey:nil];

hud.customView = imgV;

// Looks a bit nicer if we make it square.

hud.square = YES;

// Optional label text.

hud.label.text = @"Done";

[hud hideAnimated:YES afterDelay:2.f];//几秒后消失

}

#pragma mark --旋转

- (CABasicAnimation *)makeRotation{

CATransform3D rotationTransform =CATransform3DMakeRotation((360*180.0)/(M_PI), 0, 0, -1);

CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"transform"];

animation.toValue = [NSValue valueWithCATransform3D:rotationTransform];

animation.duration  =  1;

animation.autoreverses = NO;

animation.cumulative = YES;

animation.fillMode = kCAFillModeForwards;

animation.repeatCount = 100;

return animation;

}

//只有文字

- (void)textExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the text mode to show only text.

hud.mode = MBProgressHUDModeText;

hud.label.text = NSLocalizedString(@"Message here!", @"HUD message title");

// Move to bottm center.

hud.offset = CGPointMake(0.f, MBProgressMaxOffset);

[hud hideAnimated:YES afterDelay:3.f];

}

- (void)cancelationExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set the determinate mode to show task progress.

hud.mode = MBProgressHUDModeDeterminate;

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

// Configure the button.

[hud.button setTitle:NSLocalizedString(@"Cancel", @"HUD cancel button title") forState:UIControlStateNormal];

[hud.button addTarget:self action:@selector(cancelWork:)forControlEvents:UIControlEventTouchUpInside];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//小菊花--转换-->圆环

- (void)modeSwitchingExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set some text to show the initial status.

hud.label.text = NSLocalizedString(@"Preparing...", @"HUD preparing title");

// Will look best, if we set a minimum size.

hud.minSize = CGSizeMake(150.f, 100.f);

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

// Do something useful in the background and update the HUD periodically.

[self doSomeWorkWithMixedProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

- (void)networkingExample {

MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.view animated:YES];

// Set some text to show the initial status.

hud.label.text = NSLocalizedString(@"Preparing...", @"HUD preparing title");

// Will look best, if we set a minimum size.

hud.minSize = CGSizeMake(150.f, 100.f);

[self doSomeNetworkWorkWithProgress];

}

- (void)dimBackgroundExample {

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];

// Change the background view style and color.

hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;

hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.1f];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[self doSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

- (void)colorExample {

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];

hud.contentColor = [UIColor colorWithRed:0.f green:0.6f blue:0.7f alpha:1.f];

// Set the label text.

hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[self doSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

#pragma mark - Tasks

- (void)doSomeWork {

// Simulate by just waiting.

sleep(3.);

}

iOS -- MBProgressHUB的更多相关文章

  1. iOS面试题05-父子控制器、内存管理

    内存管理.父子控制器面试题 1.建立父子关系控制器有什么用 回答:1>监听屏幕选中 2>如果想拿到你当前的很小的一个控制器所在的导航控制器必须要跟外面比较大的控制器建立父子关系,才能一层一 ...

  2. iOS可视化动态绘制连通图

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  3. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  5. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  6. iOS代码规范(OC和Swift)

    下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...

  7. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  8. 告别被拒,如何提升iOS审核通过率(上篇)

    iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...

  9. Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)

    本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...

随机推荐

  1. Android兼容性测试CTS Verifier-环境搭建、测试执行、结果分析

    CTS Verifier算是CTS的一部分,需要手动进行,主要用于测试那些自动测试系统无法测试的功能,比如相机.传感器等.由于硬件配置或其他原因,不同手机上部分测试项目被隐藏,也就是说CTS Veri ...

  2. Python属性描述符(二)

    Python存取属性的方式特别不对等,通过实例读取属性时,通常返回的是实例中定义的属性,但如果实例未曾定义过该属性,就会获取类属性,而为实例的属性赋值时,通常会在实例中创建属性,而不会影响到类本身.这 ...

  3. python基础学习笔记——循环语句(while、for)

    while 循环 流程控制语句 while 1.基本循环 while 条件: # 循环体 # 如果条件为真,那么循环则执行 # 如果条件为假,那么循环不执行   2.break break 用于退出当 ...

  4. 【Open-Falcon】Linux下安装Open-Falcon

    一.Open-Falcon组件简述 [Open-Falcon绘图相关组件] Agent:  部署在目标机器采集机器监控项 Transfer : 数据接收端,转发数据到后端Graph和Judge Gra ...

  5. java事物

    [引用:http://www.cnblogs.com/kristain/articles/2038397.html] 一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数 ...

  6. SAS描述统计量

    MEANS过程 MEAN过程默认输出的统计量有:观测总数.均值.标准差.最大值和最小值.如果要计算其他统计量或其中的某一些统计量,则可在PROC语句中指定统计量的关键字. BY语句规定了分组变量,要求 ...

  7. IDEA-常用插件,使用FindBugs寻找bug,代码分析

    bug无处不在,但是我们总希望少一点bug. 最近发现了一款好用的寻找bug的插件,特此记下. 一.安装 路径:File-->Settings-->Plugins-->Browse ...

  8. [adb 学习篇] python将adb命令集合到一个工具上

    https://testerhome.com/topics/6938 qzhi的更全面,不过意思是一样的,另外补充一个开源的https://github.com/264768502/adb_wrapp ...

  9. [LOJ#525]「LibreOJ β Round #4」多项式

    [LOJ#525]「LibreOJ β Round #4」多项式 试题描述 给定一个正整数 k,你需要寻找一个系数均为 0 到 k−1 之间的非零多项式 f(x),满足对于任意整数 x 均有 f(x) ...

  10. bzoj 1038 瞭望塔 半平面交+分段函数

    题目大意 给你一座山,山的形状在二维平面上为折线 给出\((x_1,y_1),(x_2,y_2)...(x_n,y_n)\)表示山的边界点或转折点 现在要在\([x_1,x_n]\)(闭区间)中选择一 ...