Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cocoa

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

spinner image

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

inverted spinner image

How would I go about doing this? My last resort would be to write my own custom NSView subclass that renders a custom animation, but I'm not even sure where to start on that front. Any help is appreciated.

like image 776
e.James Avatar asked Jan 19 '09 03:01

e.James


4 Answers

This is what I've done:

    #import <QuartzCore/QuartzCore.h>

    ...

    CIFilter *lighten = [CIFilter filterWithName:@"CIColorControls"];
    [lighten setDefaults];
    [lighten setValue:@1 forKey:@"inputBrightness"];
    [self.indicator setContentFilters:[NSArray arrayWithObjects:lighten, nil]];
like image 141
Steve Avatar answered Nov 05 '22 15:11

Steve


I actually have implemented clones of the spinning NSProgressIndicator that might suit your needs. They can be drawn at any size and in any color. One is a subclass of NSView, which can be used on OS X 10.4, and the other is a subclass of CALayer, which can be used in a CoreAnimation-based project. The code is on github (both the NSView-based version and the CoreAnimation-based version), and there is a post with some screenshots on my blog.

like image 30
Kelan Avatar answered Nov 05 '22 15:11

Kelan


Not sure if this would work correctly with NSProgressIndicator, but you might try using a Core Image filter to invert the display of the progress indicator view. You would have to make the view layer backed, and then add a CIFilter to its layer's filters. You may be able to do this all in the effects inspector in Interface Builder, otherwise you could also just do it in code.

like image 15
Brian Webster Avatar answered Nov 05 '22 14:11

Brian Webster


While I'm sure that Kelan's code worked a while ago, it's difficult to update. I ended up going with ITProgressIndicator, and it took about 2 minutes to get working using Xcode 6 (Beta 1) and Yosemite (Beta 2).

like image 5
Adam Fox Avatar answered Nov 05 '22 14:11

Adam Fox