iOS -- MBProgressHUB

摘要:
高级:http://www.jianshu.com/p/485b8d75ccd4//只有小菊花-(空)不确定示例{//在根视图中显示HUD(自视图是可滚动的表格视图,不适合,//因为HUD会随着内容滚动)。MBPr

高级: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.viewanimated: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

[selfdoSomeWork];

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

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

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

//小菊花+文字

- (void)labelExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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), ^{

[selfdoSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

//小菊花+文字+detailsLabel

- (void)detailsLabelExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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 (1/1)",@"HUD title");

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0), ^{

[selfdoSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

- (void)windowExample {

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

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

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0), ^{

[selfdoSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

//圆环进度条+文字

- (void)determinateExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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.

[selfdoSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

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

- (void)determinateNSProgressExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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 = [NSProgressprogressWithTotalUnitCount:100];

hud.progressObject= progressObject;

// Configure a cancel button.

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

[hud.buttonaddTarget: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.

[selfdoSomeWorkWithProgressObject:progressObject];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

//圆环进度条+文字

- (void)annularDeterminateExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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.

[selfdoSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

//直线进度条+文字

- (void)barDeterminateExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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.

[selfdoSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

#pragma mark --自定义视图

//自定义视图

- (void)customViewExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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 = [UIImageimageNamed:@"下拉刷新一80x80"];//success下拉刷新一80x80密码登录lgo

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

[imgV.layeraddAnimation:[selfmakeRotation]forKey:nil];

hud.customView= imgV;

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

hud.square=YES;

// Optional label text.

hud.label.text=@"Done";

[hudhideAnimated:YESafterDelay:2.f];//几秒后消失

}

#pragma mark --旋转

- (CABasicAnimation*)makeRotation{

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

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

animation.toValue= [NSValuevalueWithCATransform3D:rotationTransform];

animation.duration=1;

animation.autoreverses=NO;

animation.cumulative=YES;

animation.fillMode=kCAFillModeForwards;

animation.repeatCount=100;

returnanimation;

}

//只有文字

- (void)textExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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);

[hudhideAnimated:YESafterDelay:3.f];

}

- (void)cancelationExample {

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

// Set the determinate mode to show task progress.

hud.mode=MBProgressHUDModeDeterminate;

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

// Configure the button.

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

[hud.buttonaddTarget:selfaction:@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.

[selfdoSomeWorkWithProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

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

- (void)modeSwitchingExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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.

[selfdoSomeWorkWithMixedProgress];

dispatch_async(dispatch_get_main_queue(), ^{

[hudhideAnimated:YES];

});

});

}

- (void)networkingExample {

MBProgressHUD*hud = [MBProgressHUDshowHUDAddedTo:self.navigationController.viewanimated: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);

[selfdoSomeNetworkWorkWithProgress];

}

- (void)dimBackgroundExample {

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

// Change the background view style and color.

hud.backgroundView.style= MBProgressHUDBackgroundStyleSolidColor;

hud.backgroundView.color= [UIColorcolorWithWhite:0.falpha:0.1f];

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{

[selfdoSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

- (void)colorExample {

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

hud.contentColor= [UIColorcolorWithRed:0.fgreen:0.6fblue:0.7falpha: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), ^{

[selfdoSomeWork];

dispatch_async(dispatch_get_main_queue(), ^{

[hud hideAnimated:YES];

});

});

}

#pragma mark - Tasks

- (void)doSomeWork {

// Simulate by just waiting.

sleep(3.);

}

免责声明:文章转载自《iOS -- MBProgressHUB》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇中国知网(CNKI)验证码识别译:什么是ViewData的, ViewBag和TempData?下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

koa 搭建模块化路由/层级路由

搭建node项目目录以及基本的文件 初始化package.json文件 执行下面命令生成package.json文件 npm init --yes 创建项目目录 创建路由目录routes,存放静态资源目录public,视图目录views 安装项目所需的依赖 "dependencies": { "art-template": "^4.12.2",...

C# HTTP请求 异步(async await)

static void Main(string[] args) { new Task(() => { Invoke(); }).Start(); Console.WriteLine("我是主线...

StackExchange.Redis.DLL 操作redis加强版

直接引用StackExchange.Redis.dll这一个dll来操作redis App.config配置 <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime...

async与await总结

全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/11533174.html,多谢,=。=~  抛出3个疑问: 1、async是干哈的? 2、await在等啥? 3、await等到了又要干哈?  先说说AsyncFunction  AsyncFunction构造函数用来创建新的异步函数对象,JavaScri...

asp.net core 系列 5 项目实战之:NetCore 的 async 和 await(参考自:Microsoft教程)

十年河东,十年河西,莫欺少年穷 学无止境,精益求精 1、简介 从 VS 2012 开始,新引入了一个简化的方法,称为异步编程。我们在 >= .NETFRM 4.5 中和 Windows 运行时中使用异步,编译器它会帮助了我们降低了曾经进行的高难度异步代码编写的工作,但逻辑结构却类似于同步代码。因此,我们仅需要进行一小部分编程的工作就可以获得异步编程的...

Spring使用@Async注解

    本文讲述@Async注解,在Spring体系中的应用。本文仅说明@Async注解的应用规则,对于原理,调用逻辑,源码分析,暂不介绍。对于异步方法调用,从Spring3开始提供了@Async注解,该注解可以被标注在方法上,以便异步地调用该方法。调用者将在调用时立即返回,方法的实际执行将提交给Spring TaskExecutor的任务中,由指定的线程...