//
//  ViewController.m
//  MBProgressHUD
//
//  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;
@end

@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(, , , );
    simpleBtn.backgroundColor=[UIColor redColor];
    simpleBtn.tag=;
    [self.view addSubview:simpleBtn];

    //显示进度
    UIButton *progressBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    [progressBtn setTitle:@"进度" forState:UIControlStateNormal];
    [progressBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    progressBtn.frame=CGRectMake(, , , );
    progressBtn.backgroundColor=[UIColor redColor];
    progressBtn.tag=;
    [self.view addSubview:progressBtn];

    //自定义视图
    UIButton *customBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    [customBtn setTitle:@"自定义" forState:UIControlStateNormal];
    [customBtn addTarget:self action:@selector(customClick:) forControlEvents:UIControlEventTouchUpInside];
    customBtn.frame=CGRectMake(, , , );
    customBtn.backgroundColor=[UIColor redColor];
    customBtn.tag=;
    [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(, , , );
    windowBtn.backgroundColor=[UIColor redColor];
    windowBtn.tag=;
    [self.view addSubview:windowBtn];

    //多提示框
    UIButton *mixBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    [mixBtn setTitle:@"多提示框" forState:UIControlStateNormal];
    [mixBtn addTarget:self action:@selector(mixClick:) forControlEvents:UIControlEventTouchUpInside];
    mixBtn.frame=CGRectMake(, , , );
    mixBtn.backgroundColor=[UIColor redColor];
    mixBtn.tag=;
    [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(, , , );
    connectionBtn.backgroundColor=[UIColor redColor];
    connectionBtn.tag=;
    [self.view addSubview:connectionBtn];

}
//普通
-(void)btnClick:(id)sender
{
    UIButton *btn=(UIButton *)sender;

    _hud=[[MBProgressHUD alloc]initWithView:self.view];
    _hud.delegate=self;
    _hud.labelText=@"Loading";
    _hud.detailsLabelText=@"updating data";
    _hud.square=YES;
    //默认
    _hud.mode=MBProgressHUDModeIndeterminate;
    ) {
        _hud.mode=MBProgressHUDModeDeterminateHorizontalBar;
    }
    [self.view addSubview:_hud];

    [_hud showAnimated:YES whileExecutingBlock:^{
        ) {
             sleep();
        }
        )
        {
            [self myProgressTask];
        }

    } completionBlock:^{
        [_hud removeFromSuperview];
    }];

}
//自定义视图
-(void)customClick:(id)sender
{
    _hud = [[MBProgressHUD alloc] initWithView:self.view];
    [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:];

}

//window视图
-(void)windowClick:(id)sender
{
    _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, );
    _currentLength=;

}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    _currentLength+=[data length];
    _hud.progress=_currentLength/(float)_expectedLength;

}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    _hud.customView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
    _hud.mode=MBProgressHUDModeCustomView;
    [_hud hide:YES afterDelay:];
}
-(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();
    }

}
-(void)task
{
    sleep();
}
-(void)mixedTask
{
    _hud.mode=MBProgressHUDModeIndeterminate;
    _hud.labelText=@"Progressing";
    float progress=0.0f;
    while (progress<1.0f) {
        progress+=0.1f;
        _hud.progress=progress;
        usleep();
    }
    // Back to indeterminate mode
    _hud.mode = MBProgressHUDModeIndeterminate;
    _hud.labelText = @"Cleaning up";
    sleep();
    // 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();
}
- (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的更多相关文章

  1. iOS 第三方框架-MBProgressHUD

    MBProgressHUD提示框官网地址:https://github.com/jdg/MBProgressHUD 官网里已经提供了足够多的例子供我们使用,但在实现开发中,我们用到的只是其中的一小部分 ...

  2. iOS 第三方库、插件、知名博客总结

    iOS 第三方库.插件.知名博客总结 用到的组件 1.通过CocoaPods安装 项目名称 项目信息 AFNetworking 网络请求组件 FMDB 本地数据库组件 SDWebImage 多个缩略图 ...

  3. 超全!整理常用的iOS第三方资源(转)

    超全!整理常用的iOS第三方资源 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地 ...

  4. iOS第三方库管理工具

    作者:彷徨iOS 原文地址1:http://iostree.sinaapp.com/?p=78 原文地址2:http://blog.csdn.net/wzzvictory/article/detail ...

  5. fir.im Weekly - 热门 iOS 第三方库大盘点

    本期 fir.im Weekly 收集的热度资源,大部分关于Android.iOS 开发工具.源码和脑洞大开的 UI 动画,希望给你带来更多的工作创意与灵感. 盘点国内程序员不常用的热门iOS第三方库 ...

  6. ios 第三方登录

    ios 第三方登录通常的做法是, 1.登录后,获得第三方的uid,调用服务器登录接口,如服务器返回无此用户,转2,有此用户,转3. 2.服务器返回无此用户,需完善用户资料,如果完成,则在服务器创建与第 ...

  7. 你一定能用的上的iOS第三方库

    点国内程序员不常用的热门iOS第三方库:看完,还敢自称"精通iOS开发"吗? 综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型, ...

  8. iOS第三方库

    热门iOS第三方库:看完,还敢自称”精通iOS开发”吗? 综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型,看完,还敢自称”精通iOS开发”吗? h ...

  9. IOS第三方之SVProgressHUD

    这个第三方和MBProgressHUD差不多,也挺简单的. // // ViewController.m // ProgressHUD // // Created by City--Online on ...

随机推荐

  1. [ucgui] 仪表盘函数

    /* 仪表盘 */ void DrawArcScale(void) { ; ; int i; ]; GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetPen ...

  2. Struts2-057/CVE-2018-11776两个版本RCE漏洞分析(含EXP)

    0x01 前言 2018年8月22日,Apache Strust2发布最新安全公告,Apache Struts2存在远程代码执行的高危漏洞(S2-057/CVE-2018-11776),该漏洞由Sem ...

  3. 安装webpack常见错误之一

    我安装webpack时,出现如下错误: C:\Users\admin> npm install webpack -gnpm WARN checkPermissions Missing write ...

  4. Comparable接口——容器中自定义类排序

    1.容器TreeMap,默认根据Key对象中某个属性的从小到大排列元素. (1)如下代码示例,Key是整型数字,所以按照其从小到大的顺序排列 public class TestTreeMap { pu ...

  5. extjs4.0以上添加多行工具栏的方法

    4.0.0起提供了dockedItems ,只要写两个dockItem,xtype为'toolbar',dock为 'top'即可

  6. Redis的Pub/Sub机制存在的问题以及解决方案

    Redis的Pub/Sub机制使用非常简单的方式实现了观察者模式,但是在使用过程中我们发现,它仅仅是实现了发布订阅机制,但是很多的场景没有考虑到.例如一下的几种场景: 1.数据可靠性无法保证 一个re ...

  7. php curl 伪造IP来源的实例代码

    来源:http://www.jb51.net/article/31694.htm curl 它不但可以模仿用户登录,还可以模仿用户IP地址哦,为伪造IP来源,本实例仅供参考哦 //伪造ip ; $i ...

  8. iOS----线程之间的通信

    当线程的数量大于一个的时候,线程之间可能会产生通信,既一个线程产生的结果要被另一个线程用到. 比如常用的图片的加载就是这个样子.图片的加载是在子线程进行的,当图片加载完毕,就会回到主线程中刷新UI,展 ...

  9. 5、xamarin.android 中如何对AndroidManifest.xml 进行配置和调整

    降低学习成本是每个.NET传教士义务与责任. 建立生态,保护生态,见者有份. 我们在翻看一些java的源码经常会说我们要在AndroidManifest.xml 中添加一些东西.而我们使用xamari ...

  10. Vundle,Vim 的 Bundle(转)

    长久以来,我管理 Vim 配置的方式都非常原始—— zip 打包,然后发到邮箱上.偶尔会发生忘记备份,或者配置混淆的状况,不过由于懒筋发作,竟然这个方案就这么用了两年. 终有一天,我觉得这个方法太笨了 ...