第三方库小结之进度条

这篇博客主要介绍了在iOS开发中常用的三种第三方进度条组件:MBProgressHUD、MMProgressHUD和SVProgressHUD的使用方法,包括不同展示模式、设置文字、自定义视图以及进度更新等操作。通过实例代码展示了如何在项目中集成并控制这些组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1.MBProgressHUD

/*

 MBProgressHUD 是对象方法

 先创建一个全局的MBProgressHUD

 MBProgressHUD *HUD;

 导入头文件,实现协议

 点击进去可以看到方法

 这里简单举例子

 */



    //方式1.直接在Viewshow

    HUD = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];

    HUD.delegate =self;

    //常用的设置

    //小矩形的背景色

   HUD.color = [UIColorclearColor];//这儿表示无背景

    //显示的文字

    HUD.labelText =@"Test";

    //细节文字

    HUD.detailsLabelText =@"Test detail";

    //是否有庶罩

    HUD.dimBackground =YES;

    [HUDhide:YESafterDelay:2];


    //只显示文字

    MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];

    hud.mode =MBProgressHUDModeText;

    hud.labelText =@"Some message...";

    hud.margin =10.f;

    hud.yOffset =150.f;

    hud.removeFromSuperViewOnHide =YES;  

    [hudhide:YES afterDelay:3];  

 

    

    //方式2.initWithView

    //use block

   HUD = [[MBProgressHUDalloc] initWithView:self.view];

    [self.viewaddSubview:HUD];

    HUD.labelText =@"Test";

    [HUDshowAnimated:YESwhileExecutingBlock:^{

        NSLog(@"%@",@"do somethings....");

        [selfdoTask];

    } completionBlock:^{

        [HUDremoveFromSuperview];

    }];


    

    //圆形进度条

   HUD = [[MBProgressHUDalloc] initWithView:self.view];

    [self.viewaddSubview:HUD];

    HUD.mode =MBProgressHUDModeAnnularDeterminate;

    HUD.delegate =self;

    HUD.labelText =@"Loading";

    [HUDshowWhileExecuting:@selector(myProgressTask)onTarget:selfwithObject:nilanimated:YES];


    

    //自定义view

   HUD = [[MBProgressHUDalloc] initWithView:self.view];

    HUD.customView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"37x-Checkmark.png"]];

    // Set custom view mode

    HUD.mode =MBProgressHUDModeCustomView;

    HUD.delegate =self;

    HUD.labelText =@"Completed";

    [HUDshow:YES];

    [HUDhide:YESafterDelay:3];

    

}


#pragma mark HUD的代理方法,关闭HUD时执行

-(void)hudWasHidden:(MBProgressHUD *)hud

{

    [hud removeFromSuperview];

    hud =nil;

}


-(void)doTask

{

    //你要进行的一些逻辑操作

   sleep(2);

}

//进度条

-(void) myProgressTask{

   float progress = 0.0f;

   while (progress < 1.0f) {

        progress +=0.01f;

       HUD.progress = progress;

       usleep(50000);

    }

}




2.MMProgressHUD

-(void)btnAction

{

/*

 MMProgressHUD 是类方法

 导入头文件直接使用加方法就可以了

 点击进去可以看到方法

 这里简单举例子

 */

    [MMProgressHUDshow];

    [MMProgressHUDshowWithTitle:@"yes"];

    [MMProgressHUDshowWithStatus:@"hello"];

    

}




3.SVProgressHUD

-(void)btnAction

{

/*

 SVProgressHUD 是类方法

 导入头文件直接使用加方法就可以了

 点击进去可以看到方法

 这里简单举例子

 */


    [SVProgressHUDshow]; 

    [SVProgressHUDshowErrorWithStatus:@"error"];

    [SVProgressHUDshowWithStatus:@"success"];

    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];


    [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];

}

//进度条

staticfloat progressValue =0.0f;

- (void)increateProgress

{

    progressValue +=0.1;

    [SVProgressHUDshowProgress:progressValue status:@"加载中"];

    if (progressValue <1) {

        [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];

    }else{

       [self performSelector:@selector(dismiss:)withObject:nil afterDelay:0.4];

    }

}

-(void)dismiss:(id)sender

{

    [SVProgressHUD dismiss];

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值