iOS资料一群程序猿的秘密基地Html 5+css +JavaScript

MBProgressHUD(第三方蒙版)

2016-06-19  本文已影响999人  i赵磊
请关注《[一个程序猿的秘密基地](http://www.jianshu.com/collection/7b76c71b2d73?utm_campaign=maleskine&utm_content=collection&utm_medium=reader_share&utm_source=weibo)》专题
#import "ViewController.h"
#import "MBProgressHUD.h"//导入头文件

@interface ViewController ()
@property(weak,nonatomic)MBProgressHUD *HUD;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}
//开始加载
- (IBAction)startLoad:(UIButton *)sender {
    //存在一个默认的位置坐标
    MBProgressHUD *HUD = [[MBProgressHUD alloc] init];
    [self.view addSubview:HUD];
    self.HUD=HUD;
    
    //设置指示器的样式
    //MBProgressHUDModeIndeterminate: 菊花的样式
    //MBProgressHUDModeDeterminate: 圆形的指示器
    //MBProgressHUDModeDeterminateHorizontalBar: 包含水平方向进度条的指示器
    //MBProgressHUDModeAnnularDeterminate: 圆形的指示器
    //MBProgressHUDModeCustomView: 自定义视图
    //MBProgressHUDModeText: 只显示文本的指示器
    HUD.mode = MBProgressHUDModeIndeterminate;
    
    //设置指示器的背景颜色: 默认的颜色是黑色的.
    HUD.color = [UIColor blueColor];
    
    //设置指示器的透明度: 默认值是0.8.
    //注意: 如果设置了指示器的背景颜色, 透明度属性会失效.
    //HUD.opacity = 0.2;
    
    //设置指示器的进度: 进度取值是[0, 1].0是没有进度, 1是完成时的进度.
    //HUD.progress = 0;
    
    //设置指示器出现的动画效果
    HUD.animationType = MBProgressHUDAnimationFade;
    
    //设置指示器展示的最小的时间
    HUD.minShowTime = 2;
    
    //设置展示的文本
    HUD.labelColor = [UIColor yellowColor];
    HUD.labelText = @"londing...";
    HUD.labelFont = [UIFont systemFontOfSize:13];
    
    //设置详细文本
    HUD.detailsLabelColor = [UIColor yellowColor];
    HUD.detailsLabelText = @"正在加载...";
    HUD.detailsLabelFont = [UIFont systemFontOfSize:13];
    
    //设置圆角度数
    HUD.cornerRadius = 20;
    
    //给进度指示器绑定展示进度的方法
    [HUD showWhileExecuting:@selector(addProgress) onTarget:self withObject:nil animated:YES];
    
    //设置加载完成后, 消失之后, 执行的方法
    HUD.completionBlock = ^{
        NSLog(@"消失了");
    };
    
    //展示指示器: BOOL参数表示在展示的时候, 是否需要动画效果
    [HUD show:YES];
    //隐藏
    [HUD hide:YES];
}
//停止加载
- (IBAction)stopLoad:(UIButton *)sender {
    //让指示器消失: 参数指定消失的时候是否带有动画
    //[HUD hide:YES];
    //延时多少秒再消失指示器
//    [self.HUD hide:YES afterDelay:2];
}
-(void)addProgress{
    //模拟进度量
    float progress = 0;
    while (YES) {
        if (progress < 1) {
            progress += 0.01;
            [NSThread sleepForTimeInterval:0.01];
            self.HUD.progress = progress;
        }
    }
}

效果图 一览蒙版
上一篇 下一篇

猜你喜欢

热点阅读