IOS第三方之MBProgressHUD

//
//  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(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];

}
//普通
-(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;
    if (btn.tag==10002) {
        _hud.mode=MBProgressHUDModeDeterminateHorizontalBar;
    }
    [self.view addSubview:_hud];

    [_hud showAnimated:YES whileExecutingBlock:^{
        if (btn.tag==10001) {
             sleep(3);
        }
        else if(btn.tag==10002)
        {
            [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:3];

}

//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, 1);
    _currentLength=0;

}
-(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: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);
    }

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

时间: 2024-09-08 09:04:26

IOS第三方之MBProgressHUD的相关文章

IOS第三方库ZXEasyCoding_IOS

对FastCoding做了二次封装, 实现更加便捷的存储和读取数据, 分享给大家 ZXEasyCoding 说明: 对FastCording进行封装, 更便捷存储和读取对象数据 安装: 添加ZXEasyCoder整个文件夹到项目中, #import "NSObject+ZXEasyCoder.h"即可 提醒事项: 给FastCoder关闭ARC 代码示例: //定义数据 NSArray *array = @[@"data1", @"data2"]

整理常用的iOS第三方资源

一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://github.com/jdg/MBProgressHUD 3:XML/HTML解析 地址:https://github.com/topfunky/hpple 4:有文字输入时,能根据键盘是否弹出来调整自身显示内容的位置 地址:https://github.com/michaeltyson/TPKeyboardAv

iOS第三方类库JSPatch(热更新)

---------------------------------------------------------------------------------------------------------------------------- 更新记录 2016年3月4日 JSPatch官方网址:http://jspatch.com/ OC转JS代码工具:http://bang590.github.io/JSPatchConvertor/ -------------------------

iOS网络编程-MBProgressHUD等待指示器

第三方的等待指示器,MBProgressHUD就是第三方提供的等待指示器框架.下面是MBProgressHUD提供的等待指示器样式,它们基本可以分为:未知结束时间和已知结束时间两大类等待指示器,在MBProgressHUD中可以为等待指示器添加标签和详细标签 MBProgressHUD的下载地址是https://github.com/matej/MBProgressHUD,我们将下载的源文件中的MBProgressHUD.h和MBProgressHUD.m拷贝到自己的工程中,MBProgress

iOS 第三方之流媒体

进式下载(伪流媒体) 介于下载本地播放与实时流媒体之间的一种播放形式,下载本地播放必须全部将文件下载完成后才能播放,而渐进式下载不必等到全部下载完成后再播放,它可以一边下载一边播放,在完成播放内容之后,整个文件会保存在手机上. 实时流媒体 实时流媒体是一边接收数据包一边播放,本地不保留文件副本,实时流式传输总是实时传送,可以实时实况转播,支持随机访问,用户可以快进或者快退以观看前面或后面的内容.实时流媒体传输必须保证数据包的传输速度大于文件的播放速度,否则用户看到的视频会出现暂停.当网络堵塞情况

ios第三方数据请求 UI_15

AppDelegate.m //指定根视图 self.window.rootViewController = [[[UINavigationController alloc]initWithRootViewController:[HomeViewController new]]autorelease]; 自定义cell文件: NewsCell.h #import <UIKit/UIKit.h> @class News; @interface NewsCell : UITableViewCell

IOS第三方之SDWebImage

项目中从服务器端下载图片这些几乎是必备的,使用时也很简单,只需引入SDWebImage文件 // // ViewController.m // sdWebImageDemo // // Created by City--Online on 15/6/15. // Copyright (c) 2015年 City--Online. All rights reserved. // #import "ViewController.h" #import "UIImageView+We

ios-iOS MBProgressHUD 显示问题

问题描述 iOS MBProgressHUD 显示问题 MBProgressHUD在第一次进入页面加载时,没有显示一个正常的正方形大小的view,而是显示一个类似于压缩后的十字星形状的view,如图,这是什么原因呢?求大神指教!! 解决方案 它有三个方法,你一定是选择的text的那个了,应该选择view的 解决方案二: (void)showLoadingHUDView:(UIView*)view withText:(NSString *)text { HUDView = [MBProgressH

iOS微信第三方登录实例_IOS

本文实例为大家分享了iOS微信第三方登录,供大家参考,具体内容如下 一.准备工作 1.到微信开放平台注册成开发者,获取appid 2.导入WeChatConnection.framework 3.配置URL Schemes  输入appid  例如wx29ce0f21ea982cb8 二.配置AppDelegate.m 1. 注册微信 //微信登陆 [WXApi registerApp:WeiXin_AppId withDescription:@"weixin"]; 2.设置函数 //