我在我的可可应用程序中使用"spinner"NSProgressIndicator:
我想以不同的颜色显示它,以便它在黑暗的背景上显示良好:
我该怎么做呢?我的最后一招是编写我自己的自定义NSView子类来渲染自定义动画,但我甚至不确定从哪方面开始.任何帮助表示赞赏.
Ste*_*eve 26
这就是我所做的:
#import <QuartzCore/QuartzCore.h>
...
CIFilter *lighten = [CIFilter filterWithName:@"CIColorControls"];
[lighten setDefaults];
[lighten setValue:@1 forKey:@"inputBrightness"];
[self.indicator setContentFilters:[NSArray arrayWithObjects:lighten, nil]];
Run Code Online (Sandbox Code Playgroud)
Kel*_*lan 20
我实际上已经实现了可能适合您需求的旋转NSProgressIndicator的克隆.它们可以以任何尺寸和任何颜色绘制.一个是NSView的子类,可以在OS X 10.4上使用,另一个是CALayer的子类,可以在基于CoreAnimation的项目中使用.代码在github上(基于NSView的版本和基于CoreAnimation的版本),在我的博客上有一些帖子有一些截图.
Bri*_*ter 15
不确定这是否适用于NSProgressIndicator,但您可能尝试使用Core Image过滤器来反转进度指示器视图的显示.您必须支持视图层,然后将CIFilter
其添加到其图层的过滤器.您可以在Interface Builder中的效果检查器中完成所有操作,否则您也可以在代码中执行此操作.
对于更精细的解决方案,您可以使用以下类别的多项式颜色方法.请注意,为简单起见,我只使用向量的x分量.有关更准确的颜色匹配,请参阅参考:https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIColorMatrix
@import QuartzCore;
#import <Cocoa/Cocoa.h>
@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
Run Code Online (Sandbox Code Playgroud)