DockProgress

在您的应用程序的 Dock 图标中显示进度

要求

macOS 10.15+

安装

在 Xcode 的 “Swift Package Manager”选项卡中添加 https://github.com/sindresorhus/DockProgress

最新版本: 4.3.1

API

查看 API 文档。

用法

手动设置进度

import DockProgress

foo.onUpdate = { progress in
	DockProgress.progress = progress
}

指定一个 Progress 实例

import Foundation
import DockProgress

let progress = Progress(totalUnitCount: 1)
progress?.becomeCurrent(withPendingUnitCount: 1)

DockProgress.progressInstance = progress

给定的 Progress 实例会被弱引用存储。 您需要负责保留它。

样式

它带有五种样式。 欢迎提交 PR 以添加更多样式。

查看 Xcode 项目中的示例应用程序。

您也可以使用 .custom(drawHandler: (_ rect: CGRect) -> Void) 绘制自定义进度。

条形 (Bar)

import DockProgress

DockProgress.style = .bar

这是默认样式。

圆角正方形 (Squircle)

import DockProgress

DockProgress.style = .squircle(color: .white.withAlphaComponent(0.5))

默认情况下,它应该完美地适合 macOS 11 及更高版本的图标,但如果您需要进行任何调整,则可以使用 inset 参数。

圆形 (Circle)

import DockProgress

DockProgress.style = .circle(radius: 55, color: .systemBlue)

徽章 (Badge)

import DockProgress

DockProgress.style = .badge(color: .systemBlue, badgeValue: { getDownloadCount() })

较大的 badgeValue 数字将以千位简写表示,例如,10121k

注意: badgeValue 不适合用作数字百分比。 它适用于诸如下载计数、正在转换的文件数等。

饼图 (Pie)

import DockProgress

DockProgress.style = .pie(color: .systemBlue)

相关