效果预览

demo_v4.gif

安装

可使用cocoapods安装

pod "HDHUD"

一个简单的Toast,使用swift封装,4.0版本受ElementUI的启发,增加了序列显示的模式,从而可以展示更多的提示信息,更加灵活。优化了window的管理,从而比3.0版本更加高效,且不依赖其他第三方库。

特色

  • 简单易用,性能高效
  • 支持序列显示和单独显示,内容自适应
  • 配置灵活,UI支持各类配置
  • 干净纯粹,无依赖

显示提示

//plain text
HDHUD.show("纯文本展示")

//only icon
HDHUD.show(icon: .loading)

//文本加icon
HDHUD.show("错误信息", icon: .error)

//进度条显示
let task = HDHUD.show(progress: 0.3)
//更新进度条
task.progress = task.progress + 0.3

隐藏hud提示

//隐藏全部
HDHUD.hide()

//隐藏指定信息
let task = HDHUD.show("竖版排列")
HDHUD.hide(task: task)

修改为单条显示

默认为多条显示,如果需要传统的单条显示方式,可以设置

HDHUD.displayType = .single

更多配置项

open class HDHUD {
    public static var displayPosition: HDHUDDisplayPosition = .top
    public static var displayType: HDHUDDisplayTypee = .sequence
    ///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: 18, height: 18)
    ///color and text
    public static var contentBackgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
    public static var backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.2)
    public static var textColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.00)
    public static var textFont = UIFont.systemFont(ofSize: 16)
    public static var contentOffset = CGPoint.zero
    public static var progressTintColor = UIColor(red: 1.0, green: 0.6, blue: 0.0, alpha: 1.00)
    public static var trackTintColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.00)
    public static var isMask = false
}

关闭按钮

2025-10-13T06:56:38.png

closeButtonDelay大于0时,会延迟显示手动关闭的按钮,例如数据上传,避免界面长时间无响应影响用户体验,当为-1时不会显示,为0时会立即显示,点击会关闭该条toast

Project

github: https://github.com/DamonHu/HDHUD

最后修改:2025 年 10 月 13 日
请我喝杯可乐,请随意打赏: ☞已打赏列表