FlyHUD: Easy-to-use HUD in Swift FlyHUD: Easy-to-use HUD in Swift

Swift Platforms CocoaPods SPM Carthage Doc License

英文 | 简体中文

这是一个轻量级且易于使用的HUD,旨在显示iOS和tvOS上正在进行的任务的进度和状态。

屏幕截图

要求

安装

Swift Package Manager

...使用 swift build

如果您正在使用 Swift Package Manager,请将依赖项添加到您的 Package.swift 文件中,并将 HUD 库导入到所需的目标中

dependencies: [
    .package(url: "https://github.com/liam-i/FlyHUD.git", from: "1.5.12")
],
targets: [
    .target(
        name: "MyTarget", dependencies: [
            .product(name: "FlyHUD", package: "FlyHUD"),         // Optional
            .product(name: "FlyProgressHUD", package: "FlyHUD"), // Optional
            .product(name: "FlyIndicatorHUD", package: "FlyHUD") // Optional
        ])
]

...使用 Xcode

如果您正在使用 Xcode,那么您应该

提示

有关详细教程,请参阅: Apple 文档

CocoaPods

如果您正在使用 CocoaPods,请将其添加到您的 Podfile

source 'https://github.com/CocoaPods/Specs.git'
# Or use CND source
# source 'https://cdn.cocoapods.org/'
platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
  # Use the FlyHUD, FlyIndicatorHUD and FlyProgressHUD components.
  pod 'FlyHUD', '~> 1.5.12'

  # Or, just use the FlyHUD component.
  pod 'FlyHUD', '~> 1.5.12', :subspecs => ['FlyHUD']

  # Or, just use the FlyHUD and FlyIndicatorHUD components.
  pod 'FlyHUD', '~> 1.5.12', :subspecs => ['FlyIndicatorHUD']

  # Or, just use the FlyHUD and FlyProgressHUD components.
  pod 'FlyHUD', '~> 1.5.12', :subspecs => ['FlyProgressHUD']
end

并运行 pod install

重要

需要 CocoaPods 1.13.0 或更高版本。

Carthage

如果您正在使用 Carthage,请将其添加到您的 Cartfile

github "liam-i/FlyHUD" ~> 1.5.12

并运行 carthage update --platform iOS --use-xcframeworks

用法

在您的应用程序中使用 HUD 非常简单。

let hud = HUD.show(to: view)
DispatchQueue.global().async {
    // Do something...
    DispatchQueue.main.async {
        hud.hide()
    }
}
let hud = HUD.show(to: view, mode: .progress(), label: "Loading")
Task.request { progress in
    hud.progress = progress
} completion: {
    hud.hide()
}
HUD.showStatus(to: view, label: "Wrong password")
HUD.showStatus(to: view, mode: .custom(UIImageView(image: UIImage(named: "Checkmark")?.withRenderingMode(.alwaysTemplate))), label: "Completed")
HUD.showStatus(to: view, mode: .custom(UIImageView(image: UIImage(named: "warning"))), label: "You have an unfinished task.") {
    $0.contentView.indicatorPosition = .leading
}
HUD.showStatus(to: view, using: .animation(.slideUpDown, damping: .default, duration: 0.3), label: "Wrong password")
HUD.showStatus(to: view, label: "You have a message.") {
    $0.keyboardGuide = .center()
}

警告

HUD 是一个 UI 类,因此应该只在主线程上访问。

有关更多示例,包括如何将 HUD 与异步操作(如 URLSession)一起使用,以及如何自定义 HUD 样式,请查看捆绑的示例项目。详细的 API 文档可在此处获取: here

要运行示例项目,请首先克隆 repo,然后 cd 到根目录并运行 pod install。然后在 Xcode 中打开 HUD.xcworkspace。

文档

发布版本和 main 的文档可在此处获取

其他版本

为什么叫 FlyHUD 这个名字?

FlyHUD 这个名字结合了 FlyHUD,并以其简洁性和表达性而著称。Fly 意味着快速、高效和灵活,这与 HUD 的实时性和即时性相一致。总的来说,FlyHUD 表达了 HUD 快速有效地呈现信息和数据的能力。

致谢

许可证

FlyHUD 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。