Skip to content

Instantly share code, notes, and snippets.

@berkcebi
Created August 23, 2018 00:45
Show Gist options
  • Save berkcebi/e0f09d5ea3b95ad3230b0995435ec151 to your computer and use it in GitHub Desktop.
Save berkcebi/e0f09d5ea3b95ad3230b0995435ec151 to your computer and use it in GitHub Desktop.
Changing the color of a spinning `NSProgressIndicator` using Core Image filters.
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]
}
}
@berkcebi
Copy link
Author

berkcebi commented Mar 1, 2019

P.S: Adding this filter on Mojave, 10.14.3 (18D109), breaks dark appearance background color tinting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment