HDHUD
中文文档
屏幕截图
集成
使用 cocoapods
进行集成
pod "HDHUD"
特点
- 易于使用,通过不同的参数实现不同的显示效果
- 纯文本显示
- 带有图标显示,图标的位置和图片支持自定义
- 进度条显示
- 加载显示
- 自适应文本大小
- 多个弹窗窗口序列显示,叠加显示,优先级显示
- 指定关闭不在指定顺序中显示的弹出窗口
显示HUD
//show HUD
static func show(_ content: String? = nil, icon: HDHUDIconType = .none, direction: HDHUDContentDirection = .horizontal, duration: TimeInterval = 2.5, superView: UIView? = nil, mask: Bool = true, priority: HDHUDPriority = .high, didAppear: (()->Void)? = nil, completion: (()->Void)? = nil) -> HDHUDTask
//show progress HUD
static func showProgress(_ progress: Float, direction: HDHUDContentDirection = .horizontal, superView: UIView? = nil, mask: Bool = true, priority: HDHUDPriority = .high, didAppear: (()->Void)? = nil, completion: (()->Void)? = nil) -> HDHUDProgressTask
//show customview
static func show(customView: UIView, duration: TimeInterval = 2.5, superView: UIView? = nil, mask: Bool = true, priority: HDHUDPriority = .high, didAppear: (()->Void)? = nil, completion: (()->Void)? = nil) -> HDHUDTask
使用上述功能来调用显示函数。所有参数都有默认值。可以通过不同的参数显示不同的样式,如下所示
HDHUD.show("Text Information", icon: .warn, direction: .vertical, duration: 3.0, superView: self.view, mask: true, priority: .high) {
//Automatically closed callback
}
//plain text
HDHUD.show("纯文本展示")
//only icon
HDHUD.show(icon: .loading)
content
指定要显示的弹出内容
icon
指定图标的样式,分别代表无图标、成功、失败、警告和加载
direction
可以指定图标和文本内容的排列方向。默认排列为水平或垂直
duration
指定自定义消失时间。如果传递给'-1
',则将始终显示,但在正常情况下会在提示后自动消失
superView
默认情况下,Superview是当前窗口。如果您想绑定一个视图VC,您可以传递它。这样,它将在superView销毁时销毁,从而不会有接口冲突
mask
是否可以点击壳层下面的视图。在壳层出现时,默认会有一个层掩码。您可以选择是否让掩码下的视图响应点击事件
priority
这是一个非常方便的日常使用功能。它提供了以下四个选项
public enum HDHUDPriority {
case low
case overlay
case high
case sequence
}
如果没有当前显示的Toast,这些选项都是无效的。当正在显示Toast并与显示的Toast调用display时,将按以下优先级逻辑显示
low
如果有Toast正在显示,此提示不会显示,优先级最低overlay
提示和当前显示的Toast同时叠加,两个提示将重叠high
关闭当前正在显示的Toast,并立即显示要显示的Toast。默认选项是在有多Toast的情况下,一些Toast可能在实际显示之前被隐藏。这是大多数HUD组件的逻辑sequence
在当前显示的Toast之后显示要显示的Toast,并将其添加到队列中,以确保每个提示都可以显示。如果Toast太多,用户可能需要等待很长时间
didAppear
HUD显示后的回调
completion
HUD消失后的回调
进度HUD
进度已独立优化,因此没有必要隐藏和显示
//Get progress pop-up task
let task = HDHUD.showProgress(0.1, direction: .vertical, priority: priority)
//Update progress
task.progress = 0.3
自定义视图
显示用户自定义视图的功能保留,用于显示您编写的视图
HDHUD.show(customView: customView)
注意:您需要设置自己视图的大小约束。您可以使用snapkit设置它,例如
lazy var mCustomView2: UIView = {
let view = UIView()
//设置大小
view.snp.makeConstraints { (make) in
make.width.equalTo(200)
make.height.equalTo(100)
}
return view
}()
HDHUD.show(commonView: mCustomView2)
您也可以直接使用框架设置
lazy var mCustomView: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
return view
}()
//显示
HDHUD.show(commonView: mCustomView)
显示隐藏HUD
注意:如果后续还有其他要显示的HUD,则下一个HUD将被显示
//Hide current HUD
HDHUD.hide()
//Hides the specified HUD
let task = HDHUD.show("竖版排列")
HDHUD.hide(task: task)
清除所有HUD,包括序列中未显示的
//Clear all HUDs. Completevalid sets Whether to call back the task completion when the hud in the sequence is cleared
static func clearAll(completeValid: Bool = false) {}
//for example
HDHUD.clearAll()
自定义配置
提供了许多可定制的选项,您可以轻松配置背景颜色、弹出颜色、文本颜色等
open class HDHUD {
///images
public static var warnImage = UIImageHDBoundle(named: "ic_warning")
public static var warnImageSize = CGSize(width: 24, height: 24)
public static var errorImage = UIImageHDBoundle(named: "ic_error")
public static var errorImageSize = CGSize(width: 24, height: 24)
public static var successImage = UIImageHDBoundle(named: "ic_success")
public static var successImageSize = CGSize(width: 24, height: 24)
public static var loadingImage = getLoadingImage()
public static var loadingImageSize = CGSize(width: 48, height: 48)
public static var isVibrate = false //Whether it vibrates when displaying HUD
#if canImport(Kingfisher)
//如果设置了`loadingImageURL`,加载图片将会优先使用URL资源
// If `loadingImageURL` is set, the URL resource will be used preferentially when loading images
public static var loadingImageURL: URL? = URL(fileURLWithPath: URLPathHDBoundle(named: "loading.gif") ?? "")
#endif
///color and text
public static var contentBackgroundColor = UIColor.zx.color(hexValue: 0x000000, alpha: 0.8)
public static var backgroundColor = UIColor.zx.color(hexValue: 0x000000, alpha: 0.3) {
willSet {
self.bgView.backgroundColor = newValue
}
}
public static var textColor = UIColor.zx.color(hexValue: 0xFFFFFF)
public static var textFont = UIFont.systemFont(ofSize: 16)
public static var contentOffset = CGPoint.zero
public static var progressTintColor = UIColor.zx.color(hexValue: 0xFF8F0C)
public static var trackTintColor = UIColor.zx.color(hexValue: 0xFFFFFF)
}
特别是,默认情况下,加载图标使用的是image
,系统提供的循环模式是 UIImage.animatedImage(with: imageList, duration: 0.6)
。如果您想使用GIF
图像,您可以集成此pod
pod "HDHUD/gif"
导入后,设置 HDHUD.loadingImageURL
。如果设置了 loadingImageURL
,则在加载图像时将优先使用URL资源
隐藏按钮
当HUD的duration
设置为-1
时,HUD将始终显示。为了防止出现影响用户操作的逻辑错误,当duration
为-1时,默认将在右上角添加一个关闭按钮,允许用户决定是否关闭HUD。如果您不需要此功能,可以将isShowCloseButton
设置为false
HDHUD.isShowCloseButton = false
破碎 1.3.6 -> 2.0.0
- 将
userInteractionOnUnderlyingViewsEnabled
修改为mask
,含义相反。mask
表示遮罩层下方的视图不支持点击响应,默认值是false
- 将
autoAddCloseButton
修改为isShowCloseButton
项目
github: https://github.com/DamonHu/HDHUD