Circular progress indicator for your macOS app
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CircularProgress.xcodeproj 0.2.1 Jan 31, 2019
Example Add ability to cancel the progress (#4) Jan 27, 2019
Sources/CircularProgress Tiny code formatting tweak Feb 5, 2019
.editorconfig Init Oct 18, 2018
.gitattributes Init Oct 18, 2018
.gitignore Init Oct 18, 2018
.swiftlint.yml Add SwiftLint Jan 25, 2019
CircularProgressMac.podspec 0.2.1 Jan 31, 2019
Package.swift Init Oct 18, 2018
license Init Oct 18, 2018
readme.md 0.2.1 Jan 31, 2019
screenshot-cancel.gif Improve docs for the cancel functionality Jan 27, 2019
screenshot.gif Init Oct 18, 2018

readme.md

CircularProgress

Circular progress indicator for your macOS app

This package is used in production by the Gifski and HEIC Converter app.

Requirements

  • macOS 10.12+
  • Xcode 10+
  • Swift 4.2+

Install

SwiftPM

.package(url: "https://github.com/sindresorhus/CircularProgress", from: "0.2.1")

Carthage

github "sindresorhus/CircularProgress"

CocoaPods

pod 'CircularProgressMac'

Usage

Also check out the example app in the Xcode project.

Manually set the progress

import Cocoa
import CircularProgress

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet private var window: NSWindow!

	let circularProgress = CircularProgress(size: 200)

	func applicationDidFinishLaunching(_ notification: Notification) {
		window.contentView!.addSubview(circularProgress)

		foo.onUpdate = { progress in
			self.circularProgress.progress = progress
		}
	}
}

Specify a Progress instance

import Cocoa
import CircularProgress

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet private var window: NSWindow!

	let progress = Progress(totalUnitCount: 1)

	func applicationDidFinishLaunching(_ notification: Notification) {
		window.contentView!.addSubview(circularProgress)

		progress?.becomeCurrent(withPendingUnitCount: 1)
		circularProgress.progressInstance = progress
	}
}

Cancel button

If you use the .progress property, you need to opt into the cancel button by setting .isCancellable = true. You can be notified of when the button is clicked by setting the .onCancelled property to a closure.

If you use the .progressInstance property, setting a Progress object that is isCancellable, which is the default, automatically enables the cancel button.

API

/**
Color of the circular progress view.

Defaults to the user's accent color. For High Sierra and below it uses a fallback color.
*/
@IBInspectable var color: NSColor = .controlAccentColor

/**
Show `✔` instead `100%`.
*/
@IBInspectable var showCheckmarkAtHundredPercent: Bool = true

/**
The progress value in the range `0...1`.

- Note: The value will be clamped to `0...1`.
*/
@IBInspectable var progress: Double = 0

/**
Let a `Progress` instance update the `progress` for you.
*/
var progressInstance: Progress?

/**
Reset the progress back to zero without animating.
*/
func resetProgress() {}

/**
Cancels `Progress` if it's set and prevents further updates.
*/
func cancelProgress() {}

/**
Triggers when the progress was cancelled succesfully.
*/
var onCancelled: (() -> Void)?

/**
Returns whether the progress is finished.
*/
@IBInspectable private(set) var isFinished: Bool

/**
If the progress view is cancellable it shows the cancel button.
*/
@IBInspectable var isCancellable: Bool

/**
Returns whether the progress has been cancelled.
*/
@IBInspectable private(set) var isCancelled: Bool

init(frame: CGRect) {}
init?(coder: NSCoder) {}

/**
Initialize the progress view with a width/height of the given `size`.
*/
convenience init(size: Double) {}

Related

You might also like my apps.

License

MIT © Sindre Sorhus