1

I want to show a progress bar in my application's dock icon. It works but for some reason its showing the progress bar as a grey bar, instead of the standard blue one. I used the code I found on another SO question. What am I doing wrong?

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 80.0f, 20.0f)];
[progressIndicator setStyle:NSProgressIndicatorBarStyle];
[progressIndicator setIndeterminate:NO];
[[[NSApplication sharedApplication] dockTile] setContentView:progressIndicator];
[progressIndicator setDoubleValue:50];
[[[NSApplication sharedApplication] dockTile] display];

enter image description here

Community
  • 1
  • 1
jamone
  • 17,253
  • 17
  • 63
  • 98
  • I looked at HandBrake's source and they draw the progress bar completely manually. Maybe that is what everyone does in this situation. – jamone Jul 26 '12 at 16:48

2 Answers2

2

I'm not sure this is possible without subclassing the progress indicator and doing your own drawing. I think the problem is that the dock tile is not key (and can't be?). A progress indicator in a non-key window will be gray, I assume the same is true for the dock tile. Making the progress indicator firstResponder didn't help either.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

I'm not sure why it would change but it is set by this API: setControlTint:, e.g. NSBlueControlTint to make it blue.

Kevin Grant
  • 5,363
  • 1
  • 21
  • 24
  • I tried this and it doesn't work. If you log the control tint, it logs as blue, but is's still gray. – rdelmar Jul 26 '12 at 03:31
  • Maybe you can use `dataWithPDFInsideRect:` to capture the drawing of the view, create an `NSImage` out of that, and then draw the image. (It may be necessary to first put the view in an offscreen window that you can "activate" to have the correct state drawn; I'm not sure.) – Kevin Grant Jul 26 '12 at 03:55