MBProgressHUD的使用-ios

来源:互联网 发布:北京停车软件 编辑:程序博客网 时间:2024/05/18 02:16

   每次要加载一个页面的时候都要等待几秒,那么在这几秒之中很多人都喜欢放一个进度条或者小菊花之类的东西表示正在加载,今天呢,就写一个关于进度条/小菊花的。

首先

在github上下载这个MBProgressHUD,地址https://github.com/jdg/MBProgressHUD

然后

拷贝

MBProgressHUD.h 和

MBProgressHUD.m 文件到你的工程里面,(别忘了加上头文件哦)

使用1:原始菊花类型

MBProgressHUD* hud = [[MBProgressHUD alloc]initWithView:self.view];

    [self.view addSubview:hud];

    //当前view背景颜色暗下去

    hud.dimBackground =YES;

    hud.labelText = @"haha";

[hud showAnimated:YES whileExecutingBlock:^{

            sleep(2);

        } completionBlock:^{

            [hud removeFromSuperview];

        }];


使用2:

MBProgressHUD* hud = [[MBProgressHUD alloc]initWithView:self.view];

    [self.view addSubview:hud];

    //当前view背景颜色暗下去

    hud.dimBackground =YES;

    hud.labelText = @"haha";

hud.mode = MBProgressHUDModeText;

        [hud showAnimated:YES whileExecutingBlock:^{

            float progress =0.0f;

            while (progress<1.0f) 

{

                progress += 0.01f;

                hud.progress =progress;

//                进程挂起一段时间, 单位是微秒(千分之一毫秒)

                usleep(50000);

            }

        } completionBlock:^{

            [hud removeFromSuperview];

        }];



这些全部都是一样的使用,唯一不同的是

hud.mode的选择,他有很多种

MBProgressHUDModeIndeterminate,

MBProgressHUDModeDeterminate,

MBProgressHUDModeDeterminateHorizontalBar,

MBProgressHUDModeAnnularDeterminate,

MBProgressHUDModeCustomView,

MBProgressHUDModeText

当然上面也可以同时放置文字和图片,这就是另外一个属性了

在hud.customView放一个imageView就可以了

OK,大功告成。




0 0