Swift
let adjustedTintColor = tintColor.usingColorSpace(.deviceRGB)
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")
_progress.contentFilters = [colorClampFilter]
OC
NSColor *tempColor = [[NSColor redColor] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
CGFloat temp1 = tempColor.redComponent;
CGFloat temp2 = tempColor.greenComponent;
CGFloat temp3 = tempColor.blueComponent;
CIVector *temp4 = [CIVector vectorWithX:temp1 Y:temp2 Z:temp3 W:0.0];
CIVector *temp5 = [CIVector vectorWithX:temp1 Y:temp2 Z:temp3 W:1.0];
CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorClamp"];
[colorFilter setDefaults];
[colorFilter setValue:temp4 forKey:@"inputMinComponents"];
[colorFilter setValue:temp5 forKey:@"inputMaxComponents"];
_hahah.contentFilters = @[colorFilter];
// 第二种
CIFilter *colorFilter1 = [CIFilter filterWithName:@"CIColorMonochrome"];
[colorFilter1 setDefaults];
[colorFilter1 setValue:[CIColor colorWithRed:1 green:0 blue:0 alpha:1] forKey:@"inputColor"];
[colorFilter1 setValue:@4 forKey:@"inputIntensity"];
_hahah.contentFilters = @[colorFilter1];
_hahah.doubleValue = 50.0;