zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

IOS第三方之MBProgressHUD

ios 第三方
2023-09-14 08:57:59 时间
// Created by City--Online on 15/6/15. // Copyright (c) 2015年 City--Online. All rights reserved. #import "ViewController.h" #import "MBProgressHUD.h" @interface ViewController () MBProgressHUDDelegate,NSURLConnectionDataDelegate @property(nonatomic,strong) MBProgressHUD *hud; @property(nonatomic,assign) long long expectedLength; @property(nonatomic,assign) long long currentLength; @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //普通提示框 UIButton *simpleBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [simpleBtn setTitle:@"普通" forState:UIControlStateNormal]; [simpleBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; simpleBtn.frame=CGRectMake(20, 70, 100, 100); simpleBtn.backgroundColor=[UIColor redColor]; simpleBtn.tag=10001; [self.view addSubview:simpleBtn]; //显示进度 UIButton *progressBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [progressBtn setTitle:@"进度" forState:UIControlStateNormal]; [progressBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; progressBtn.frame=CGRectMake(130, 70, 100, 100); progressBtn.backgroundColor=[UIColor redColor]; progressBtn.tag=10002; [self.view addSubview:progressBtn]; //自定义视图 UIButton *customBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [customBtn setTitle:@"自定义" forState:UIControlStateNormal]; [customBtn addTarget:self action:@selector(customClick:) forControlEvents:UIControlEventTouchUpInside]; customBtn.frame=CGRectMake(20, 180, 100, 100); customBtn.backgroundColor=[UIColor redColor]; customBtn.tag=10003; [self.view addSubview:customBtn]; //Window视图 UIButton *windowBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [windowBtn setTitle:@"Window" forState:UIControlStateNormal]; [windowBtn addTarget:self action:@selector(windowClick:) forControlEvents:UIControlEventTouchUpInside]; windowBtn.frame=CGRectMake(130, 180, 100, 100); windowBtn.backgroundColor=[UIColor redColor]; windowBtn.tag=10004; [self.view addSubview:windowBtn]; //多提示框 UIButton *mixBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [mixBtn setTitle:@"多提示框" forState:UIControlStateNormal]; [mixBtn addTarget:self action:@selector(mixClick:) forControlEvents:UIControlEventTouchUpInside]; mixBtn.frame=CGRectMake(20, 290, 100, 100); mixBtn.backgroundColor=[UIColor redColor]; mixBtn.tag=10004; [self.view addSubview:mixBtn]; //多提示框 UIButton *connectionBtn=[UIButton buttonWithType:UIButtonTypeSystem]; [connectionBtn setTitle:@"Connection" forState:UIControlStateNormal]; [connectionBtn addTarget:self action:@selector(connectionClick:) forControlEvents:UIControlEventTouchUpInside]; connectionBtn.frame=CGRectMake(130, 290, 100, 100); connectionBtn.backgroundColor=[UIColor redColor]; connectionBtn.tag=10004; [self.view addSubview:connectionBtn];
[self.view addSubview:_hud]; // Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators) _hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]]; // Set custom view mode _hud.mode = MBProgressHUDModeCustomView; _hud.delegate = self; _hud.labelText=@"Loading"; _hud.detailsLabelText=@"updating data"; _hud.square=YES; [_hud show:YES]; [_hud hide:YES afterDelay:3];
_hud=[[MBProgressHUD alloc]initWithWindow:self.view.window]; [self.view.window addSubview:_hud]; _hud.delegate=self; _hud.labelText=@"Loading"; [_hud showWhileExecuting:@selector(task) onTarget:self withObject:nil animated:YES]; //多提示框 -(void)mixClick:(id)sender _hud = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:_hud]; _hud.delegate = self; _hud.labelText = @"Connecting"; // _hud.minSize = CGSizeMake(135.f, 135.f); [_hud showWhileExecuting:@selector(mixedTask) onTarget:self withObject:nil animated:YES]; -(void)connectionClick:(id)sender NSURL *url=[NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110403/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_iPod.m4v.zip"]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:request delegate:self]; [connection start]; _hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES]; _hud.delegate=self; _hud.mode=MBProgressHUDModeDeterminate; -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response _expectedLength=MAX(response.expectedContentLength, 1); _currentLength=0;
_hud.customView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]]; _hud.mode=MBProgressHUDModeCustomView; [_hud hide:YES afterDelay:2]; -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error [_hud hide:YES]; //显示进度 - (void)myProgressTask { // This just increases the progress indicator in a loop float progress = 0.0f; while (progress 1.0f) { progress += 0.01f; _hud.progress = progress; usleep(50000);
sleep(2); // UIImageView is a UIKit class, we have to initialize it on the main thread __block UIImageView *imageView; dispatch_sync(dispatch_get_main_queue(), ^{ UIImage *image = [UIImage imageNamed:@"37x-Checkmark.png"]; imageView = [[UIImageView alloc] initWithImage:image]; _hud.customView =imageView; _hud.mode = MBProgressHUDModeCustomView; _hud.labelText = @"Completed"; sleep(2); - (void)hudWasHidden:(MBProgressHUD *)hud { // Remove HUD from screen when the HUD was hidded [_hud removeFromSuperview]; _hud=nil; - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. @end




官网里已经提供了足够多的例子供我们使用,但在实现开发中,我们用到的只是其中的一小部分而已。
IOS开发---菜鸟学习之路--(十三)-利用MBProgressHUD进行异步获取数据 本章将介绍如何利用MBProgressHUD实现异步处理数据。 其实我本来只是像实现一个加载数据时提示框的效果,然后问了学长知道了这个类,然后就使用了 接着就发现了一个“BUG” 再然后就发现原来MBProgressHUD处理数据的时候是异步处理的 而所谓的“BUG”其实是在我实现了ASIFormDataRequest 异步处理数据后 又利用MBProgressHUD来显示加载数据框所导致的。
iOS网络编程-MBProgressHUD等待指示器 p 第三方的等待指示器,MBProgressHUD就是第三方提供的等待指示器框架。下面是MBProgressHUD提供的等待指示器样式,它们基本可以分为:未知结束时间和已知结束时间两大类等待指示器,在MBProgressHUD中可以为等待指示器添加标签和详细标签 /p p align= center /p p align= center a href= http://www.
[ios开发]-APP-上架流程 由于苹果的机制,在非越狱机器上安装必须通过官方的Appstore, 开发者开发好应用后上传Appstore,也需要通过审核等环节。 AppCan作为一个跨主流平台的一个开发平台,也对ipa包上传Appstore作了支持。 本文从三个流程来介绍如何实现AppCan在 线编译出ipa包,以及上传到苹果Appstore。
社会主义 从.Net到iOS,在撸的道路上越走越远,工作之余经营着博客园http://www.cnblogs.com/5ishare,欢迎小伙伴(妹子更好)一起交流,谈谈人生理想。作为经常从网上索取免费资料的一员,要有回报回报的思想,也让更多的人少走弯路.