How can I display the spinning NSProgressIndicator in a different color?

前端 未结 9 1734
温柔的废话
温柔的废话 2020-12-03 01:27

I am using a \"spinner\" NSProgressIndicator in my cocoa app:

I would like to display it in a different color so that it will show up well on a dark backgr

9条回答
  •  被撕碎了的回忆
    2020-12-03 01:45

    For a more fine grained solution, you can use a polynomial color approach using the following Category. Please note that for simplicity I use only the x component of the vectors. For more accurate color matching please see reference at: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIColorMatrix

    @import QuartzCore;
    #import 
    
    @interface NSProgressIndicator (Colors)
    
    - (void)setCustomColor:(NSColor *)aColor;
    
    @end
    
    @implementation NSProgressIndicator (Colors)
    
    - (void)setCustomColor:(NSColor *)aColor {
        CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"];
        [colorPoly setDefaults];
    
        CIVector *redVector = [CIVector vectorWithX:aColor.redComponent Y:0 Z:0 W:0];
        CIVector *greenVector = [CIVector vectorWithX:aColor.greenComponent Y:0 Z:0 W:0];
        CIVector *blueVector = [CIVector vectorWithX:aColor.blueComponent Y:0 Z:0 W:0];
        [colorPoly setValue:redVector forKey:@"inputRedCoefficients"];
        [colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"];
        [colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"];
        [self setContentFilters:[NSArray arrayWithObjects:colorPoly, nil]];
    }
    
    @end
    

提交回复
热议问题