MBProgressHUD 使用教程

MBProgressHUD 使用教程

MBProgressHUDMBProgressHUD + Customizations项目地址:https://gitcode.com/gh_mirrors/mb/MBProgressHUD

项目介绍

MBProgressHUD 是一个为 iOS 应用添加半透明 HUD(Head-Up Display)的第三方框架。它可以在后台任务执行时显示一个带有指示器和/或标签的半透明 HUD,旨在替代 UIKit 中未公开的 UIProgressHUD,并提供一些额外的功能。MBProgressHUD 适用于 iOS 9.0 及以上版本,依赖于 Foundation、UIKit 和 CoreGraphics 框架。

项目快速启动

安装 MBProgressHUD

使用 CocoaPods

在你的 Podfile 中添加以下内容:

pod 'MBProgressHUD', '~> 1.2.0'

然后运行 pod install

使用 Carthage

在你的 Cartfile 中添加以下内容:

github "jdg/MBProgressHUD" ~> 1.2.0

然后运行 carthage update,并按照 Carthage 的标准安装指南将 MBProgressHUD 添加到你的项目中。

基本使用

在你的代码中导入 MBProgressHUD:

#import "MBProgressHUD.h"

显示 HUD:

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // 执行后台任务
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    });
});

应用案例和最佳实践

显示自定义消息

你可以显示带有自定义消息的 HUD:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.label.text = @"加载中...";
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // 执行后台任务
    dispatch_async(dispatch_get_main_queue(), ^{
        [hud hideAnimated:YES];
    });
});

显示完成消息

在任务完成后显示一条完成消息:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.label.text = @"完成";
hud.mode = MBProgressHUDModeText;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // 执行后台任务
    dispatch_async(dispatch_get_main_queue(), ^{
        [hud hideAnimated:YES afterDelay:1.5];
    });
});

典型生态项目

MBProgressHUD 作为一个常用的 HUD 显示框架,广泛应用于各种 iOS 应用中,尤其是需要长时间后台任务处理的应用。它简单易用,且提供了丰富的自定义选项,使得开发者可以根据需要灵活调整 HUD 的显示效果。

相关项目

  • SVProgressHUD:另一个流行的 HUD 显示框架,提供了类似的功能。
  • JGProgressHUD:一个功能更丰富的 HUD 框架,支持更多的自定义选项和动画效果。

通过这些项目,开发者可以更好地理解和掌握 HUD 的使用,提升用户体验。

MBProgressHUDMBProgressHUD + Customizations项目地址:https://gitcode.com/gh_mirrors/mb/MBProgressHUD

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

左萱莉Maude

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值