Skip to content

Instantly share code, notes, and snippets.

@hechen
Created March 18, 2019 07:33
Show Gist options
  • Save hechen/13d04d70b0556cbbafb2d69a4f9a407c to your computer and use it in GitHub Desktop.
Save hechen/13d04d70b0556cbbafb2d69a4f9a407c to your computer and use it in GitHub Desktop.
NSProgressIndicator loading extension
#if os(macOS)
import Cocoa
/// Add loading property for NSProgressIndicator
extension NSProgressIndicator {
struct Holder {
static var _loading: Bool = false
static var _hideWhenAnimationStop: Bool = false
}
var hideWhenAnimationStop: Bool {
get {
return Holder._hideWhenAnimationStop
}
set {
Holder._hideWhenAnimationStop = newValue
}
}
var loading: Bool {
get {
return Holder._loading
}
set {
isHidden = false
Holder._loading = newValue
if newValue {
startAnimation(nil)
} else {
stopAnimation(nil)
if hideWhenAnimationStop { isHidden = true }
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment