高级: 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. linux内核代码注释 赵炯 第三章引导启动程序

    linux内核代码注释 第三章引导启动程序 boot目录中的三个汇编代码文件   bootsect.s和setup.s采用近似intel的汇编语法,需要8086汇编器连接器as86和ld86 head ...

  2. Wannafly挑战赛9

    链接:https://www.nowcoder.com/acm/contest/71/A来源:牛客网 找一找 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5 ...

  3. Set容器——TreeSet及常用API

    TreeSet及常用Api ①   TreeSet为使用树来进行存储的Set接口提供了一个工具,对象按升序存储,访问和检索很快; ②   在存储了大量的需要进行快速检索的排序信息的情况下,TreeSe ...

  4. HDU——1418抱歉(平面欧拉公式)

    抱歉 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  5. 设计模式(Java随笔)—装饰模式

    装饰模式(Decorator Pattern):为已有功能动态地添加更多功能的一种方式Attach additional responsiblities to an object dynamicall ...

  6. mac上安装chromedriver

    默认下载2.35版本,放置到/usr/local/bin #!/usr/bin/env bash # ------------------------------------------------- ...

  7. 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作(转)

    马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...

  8. vue2 vuex 简单入门基础

    1.vuex中文文档 https://vuex.vuejs.org/zh-cn/api.html 2.我理解vuex 应用观察者模式 设置了全局的状态 state 状态变化即通知更新全局state 3 ...

  9. Linux 设备驱动的固件加载【转】

    转自:http://blog.csdn.net/zqixiao_09/article/details/51106663 版权声明:本文为博主原创文章,未经博主允许不得转载. 作为一个驱动作者, 你可能 ...

  10. fuelgauge

    void fg_init(void *queue, void (*bs_fuel_gauge_status)(void)) { fg_init_ready = bs_fuel_gauge_status ...