MBProgressHUD

[size=large]
1,将MBProgressHUD.h 和MBProgressHUB.m 两个文件添加到项目当中:


2,开始相关编码:


//
// ViewController.m
// MBProgressHUDDemo
//
// Created by 陈海涛 on 13-7-29.
// Copyright (c) 2013年陈海涛. All rights reserved.
//

#import "ViewController.h"
#import "MBProgressHUD.h"
#import "ASIHTTPRequest.h"

@interface ViewController ()

//HUD(Head-Up Display, 意思是抬头显示的意思)
@property (nonatomic,strong) MBProgressHUD *hud;

@end

@implementation ViewController

- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)showTextAction:(id)sender {
//初始化进度框,设置于当前的view中
self.hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];

//设置背景为暗淡得
self.hud.dimBackground = YES;

//设置对话框文字
self.hud.labelText = @"加载中。。。。";
self.hud.mode = MBProgressHUDModeIndeterminate;

[self.hudshow:YES];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithString: @"https://www.ifeng.com"]];
[NSURLConnectionsendAsynchronousRequest:request queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"%@,%@",response,data);
dispatch_async(dispatch_get_main_queue(), ^{
[self.hudremoveFromSuperview];
self.hud = nil;
});
}];

});

}


- (IBAction)showProgressAction1:(id)sender {

self.hud = [[MBProgressHUDalloc] initWithView:self.view];
[self.view addSubview:self.hud];
//设置hud的出现的动画效果
self.hud.animationType = MBProgressHUDAnimationZoom;
self.hud.removeFromSuperViewOnHide = YES;
self.hud.mode =MBProgressHUDModeIndeterminate;
self.hud.labelText = @"开始。。。";
[self.hudshow:YES];


ASIHTTPRequest *request = [[ASIHTTPRequestalloc] initWithURL:[NSURLURLWithString:@"https://github.com/matej/MBProgressHUD/zipball/master"]];


__blockASIHTTPRequest *request2 = request;

[request setHeadersReceivedBlock:^(NSDictionary *responseHeaders) {
self.hud.mode = MBProgressHUDModeDeterminate;
self.hud.labelText = @"下载。。。";
[request2 setDownloadProgressDelegate:self.hud];
}];

[request setCompletionBlock:^{
NSLog(@"success");
self.hud.mode = MBProgressHUDModeCustomView;
self.hud.labelText = @"成功。。。";
self.hud.customView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"Checkmark.png"]];
[self.hudhide:YES afterDelay:1];
[request2.responseDatawriteToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"123.zip"] atomically:YES];
}];

[request setFailedBlock:^{
NSLog(@"fail");
self.hud.mode = MBProgressHUDModeCustomView;
self.hud.labelText = @"失败。。。";
self.hud.customView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"fail.jpeg"]];
[self.hudhide:YES afterDelay:1];
}];


[request startAsynchronous];

}



- (IBAction)showProgressAction2:(id)sender {

self.hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.hud];
self.hud.labelText = @"正在下载,请稍等";
self.hud.color = [UIColor grayColor];

self.hud.mode = MBProgressHUDModeAnnularDeterminate;
[self.hud show:YES];


ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"https://github.com/matej/MBProgressHUD/zipball/master"]];
request.downloadProgressDelegate = self.hud;

[request startAsynchronous];

}


@end



[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值