ZVProgressHUD 3.0.6

ZVProgressHUD 3.0.6

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released最后发布2021年10月
SPM支持SPM

Zev维护。



  • zevwings

ZVProgressHUD

Carthage compatible CocoaPods Compatible Platform

ZVProgressHUD是一个纯Swift的轻量级HUD。

中文文档

要求

  • iOS 8.0+
  • Swift 5.0

演示

您可以在Appetize上运行此演示。

安装

CocoaPod

CocoaPods 是 Swift 和 Objective-C Cocoa 项目的依赖管理器。

您可以使用以下命令安装 Cocoapods

$ sudo gem install cocoapods

要使用 CocoaPods 将 ZVProgressHUD 集成到您的项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
    use_frameworks!
    pod 'ZVProgressHUD', '~> 2.0.0'
end

然后,使用 CocoaPods 安装您的依赖项。

$ pod install

Carthage

Carthage 旨在成为向您的应用程序添加框架的最简单方式。

您可以使用以下命令通过 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 ZVProgressHUD 集成到您的项目中,请在您的 Cartfile 中指定它

github "zevwings/ZVProgressHUD" ~> 0.0.1

然后,使用 carthage update 命令构建框架并将其拖入您的项目中的 ZVProgressHUD.framework

注意

框架位于 Carthage/Build 目录下,您应该将其拖入 目标 -> 常规 -> 嵌入的二进制文件

用法

当您需要使用 ZVProgressHUD 时,您可以使用 import ProgressHUD

显示 HUD

当您开始一个任务时,您可以使用以下代码

// class method
ProgressHUD.shared.show()
// or you can use instance method 
let hud = ProgressHUD()
hud.show()

您可以根据需要自定义动画类型,使用以下代码

/// the animation type, default is flat
public enum AnimationType {
	case flat		
	case native	
}

/// this code will modify global animation type.
ProgressHUD.shared.animationType = .flat

当您想修改 ZVProgressHUD 的父视图时,请使用以下代码

// the HUD will show delay 0.0
ZVProgressHUD.show(with: "Loading", in: superview, delay: 0.0)

关闭 HUD

您可以使用简单的代码来关闭 HUD。

// class method
ProgressHUD.shared.dismiss()
// or you can use instance method 
hud.dismiss()

显示确认框

当您需要显示确认信息时,请使用以下代码

ProgressHUD.shared.showError(with: "error")
ProgressHUD.shared.showSuccess(with: "success")
ProgressHUD.shared.showWarning(with: "warning")

显示自定义图片

您也可以显示自定义图片,使用以下代码

let image = UIImage(named: "smile")
ProgressHUD.shared.showImage(image!)
// or
ProgressHUD.shared.showImage(image!, title: "smile everyday!")

显示自定义动画

您可以使用以下代码自定义动画指示器。

var images = [UIImage]()
for index in 1 ... 3 {
    let image = UIImage(named: "loading_0\(index)")
    images.append(image!)
}

ProgressHUD.shared.showAnimation(images)

显示进度

ProgressHUD.shared.showProgress(0.0, title: "Progress")

自定义标志

// set logoSize of HUD, CGSize(30, 30)
class var logoSize: CGSize 
// set logo image of HUD, default is nil
class var logo: UIImage 

自定义属性

// set displayStyle type of HUD, default is dark.
class var displayStyle: DisplayStyle 

// set mask type of HUD
class var maskType: MaskType 

// the cornerRadius of basic view   
class var cornerRadius: CGFloat 

// the offset of basic view
class var offset: UIOffset 

// the font of title label
class var font: UIFont 

// you can change the line width of indicator when animation type is `flat`
class var strokeWith: CGFloat 

// the size of indicator
class var indicatorSize: CGSize 

// the animation type, default is `flat`
class var animationType: IndicatorView.AnimationType 

内容自定义内边距

class var contentInsets: UIEdgeInsets 

class var titleEdgeInsets: UIEdgeInsets 

class var indicatorEdgeInsets: UIEdgeInsets 

通知

您可以在 HUD 的通知中添加一个观察者来执行某些操作。

extension NSNotification.Name {
	
	 // this hud did disappear
    public static let ProgressHUDReceivedTouchUpInsideEvent: Notification.Name

	 // this hud will appear
    public static let ProgressHUDWillAppear: Notification.Name

	 // this hud did appear
    public static let ProgressHUDDidAppear: Notification.Name

	 // this hud will disappear
    public static let ProgressHUDWillDisappear: Notification.Name

	 // this hud did disappear
    public static let ProgressHUDDidDisappear: Notification.Name
}

许可证

ZVProgressHUD 在 MIT 许可证条款和条件下分发