Created
August 23, 2018 00:45
-
-
Save berkcebi/e0f09d5ea3b95ad3230b0995435ec151 to your computer and use it in GitHub Desktop.
Changing the color of a spinning `NSProgressIndicator` using Core Image filters.
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
extension NSProgressIndicator { | |
func set(tintColor: NSColor) { | |
guard let adjustedTintColor = tintColor.usingColorSpace(.deviceRGB) else { | |
contentFilters = [] | |
return | |
} | |
let tintColorRedComponent = adjustedTintColor.redComponent | |
let tintColorGreenComponent = adjustedTintColor.greenComponent | |
let tintColorBlueComponent = adjustedTintColor.blueComponent | |
let tintColorMinComponentsVector = CIVector(x: tintColorRedComponent, y: tintColorGreenComponent, z: tintColorBlueComponent, w: 0.0) | |
let tintColorMaxComponentsVector = CIVector(x: tintColorRedComponent, y: tintColorGreenComponent, z: tintColorBlueComponent, w: 1.0) | |
let colorClampFilter = CIFilter(name: "CIColorClamp")! | |
colorClampFilter.setDefaults() | |
colorClampFilter.setValue(tintColorMinComponentsVector, forKey: "inputMinComponents") | |
colorClampFilter.setValue(tintColorMaxComponentsVector, forKey: "inputMaxComponents") | |
contentFilters = [colorClampFilter] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
P.S: Adding this filter on Mojave, 10.14.3 (18D109), breaks dark appearance background color tinting.