iOS——MBProgressHUD的使用方法
来源:互联网 发布:大数据建设 编辑:程序博客网 时间:2024/06/05 12:03
MBProgressHUD就是一个非常好用的第三方库,可以快速接入加载的界面,下面贴代码,下面的代码包含了各种常用类型的加载:
#import "ViewController.h"#import "MBProgressHUD.h"@interface ViewController ()@property (atomic, assign) BOOL canceled;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}//仅显示加载的图标- (IBAction)indeterminateExample:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ [self doSomeWork]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); });}- (IBAction)With_details_label:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title"); 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]; }); });}- (IBAction)With_label:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.label.text = @"正在加载"; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ [self doSomeWork]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); });}- (IBAction)Circle_style:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeDeterminate; hud.label.text = @"正在加载"; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ [self doSomeWorkWithProgress]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); });}- (IBAction)Progress_style:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeDeterminateHorizontalBar; hud.label.text = @"正在加载"; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ [self doSomeWorkWithProgress]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); });}- (IBAction)Text_only:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeText; hud.label.text = @"正在加载"; hud.offset = CGPointMake(0.f, MBProgressMaxOffset); [hud hideAnimated:YES afterDelay:3.f];}- (IBAction)With_action_button:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeDeterminate; hud.label.text = @"正在加载"; [hud.button setTitle:@"取消" forState:UIControlStateNormal]; [hud.button addTarget:self action:@selector(cancelWork:) forControlEvents:UIControlEventTouchUpInside]; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ [self doSomeWorkWithProgress]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); });}- (IBAction)Custom_view:(id)sender{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeCustomView; UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; hud.customView = [[UIImageView alloc] initWithImage:image]; hud.square = YES; hud.label.text = @"已完成"; [hud hideAnimated:YES afterDelay:1.5f];}- (void)doSomeWorkWithProgress { self.canceled = NO; float progress = 0.0f; while (progress < 1.0f) { if (self.canceled) break; progress += 0.01f; dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD HUDForView:self.view].progress = progress; }); usleep(50000); }}-(void)doSomeWork{ //加载时候处理的事件和方法 NSLog(@"正在加载"); //显示加载的时间 sleep(1.5);}- (void)cancelWork:(id)sender { self.canceled = YES;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
以上是全部代码,效果图如下:
上面的源码博主有上传到github上,若感兴趣可以点击前往下载。
0 0
- iOS——MBProgressHUD的使用方法
- iOS MBProgressHUD 的使用方法
- MBProgressHUD的使用方法
- iOS开发——MBProgressHUD
- iOS ----- MBProgressHUD、SVProgressHUD基本使用方法
- 【iphone开发】MBProgressHUD的使用方法
- iOS MBProgressHUD的使用
- MBProgressHUD的使用-ios
- iOS开发之进度条——MBProgressHUD
- iOS开发——MBProgressHUD 与 SVProgressHUD iOS提示框的优缺点
- iOS: MBProgressHUD的一个exception
- ios 指示器MBProgressHUD 的使用
- ios MBProgressHUD的基本使用
- iOS MBProgressHUD的简单使用
- 更新MBProgressHUD后的基本使用方法
- 开源中国iOS客户端学习——MBProgressHUD特效
- iOS开发——使用MBProgressHUD来增加用户体验
- ios MBProgressHUD
- Chrome谷歌浏览器插件,Request Maker,用来模拟http 请求,这个插件怎么使用?
- storm on yarn 部署
- Robomongo需要mongo认证的解决方法
- 为什么我获取不到这个css样式?js原生获取css样式总结
- python中的import,reload,以及__import__
- iOS——MBProgressHUD的使用方法
- 验证码自动识别的基础知识汇总
- XXX.EXE已停止工作
- vim 正则表达式替换 简单例子
- SimpleDateFormat函数语法:
- OpenGL--天空盒
- SearchView本地实时搜索
- 01-Popover跳转
- 对before和after这 两个伪类的理解