Created
March 18, 2019 07:33
-
-
Save hechen/13d04d70b0556cbbafb2d69a4f9a407c to your computer and use it in GitHub Desktop.
NSProgressIndicator loading extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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