在您的应用程序的 Dock 图标中显示进度
macOS 10.15+
在 Xcode 的 “Swift Package Manager”选项卡中添加 https://github.com/sindresorhus/DockProgress
。
最新版本: 4.3.1
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)
绘制自定义进度。
import DockProgress
DockProgress.style = .bar
这是默认样式。
import DockProgress
DockProgress.style = .squircle(color: .white.withAlphaComponent(0.5))
默认情况下,它应该完美地适合 macOS 11 及更高版本的图标,但如果您需要进行任何调整,则可以使用 inset
参数。
import DockProgress
DockProgress.style = .circle(radius: 55, color: .systemBlue)
import DockProgress
DockProgress.style = .badge(color: .systemBlue, badgeValue: { getDownloadCount() })
较大的 badgeValue
数字将以千位简写表示,例如,1012
→ 1k
。
注意: badgeValue
不适合用作数字百分比。 它适用于诸如下载计数、正在转换的文件数等。
import DockProgress
DockProgress.style = .pie(color: .systemBlue)