Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSProgressIndicator can't set background color to white

When I set my progress indicator's background to green, it works as expected.

Code:

loadingIndicator.wantsLayer = true
loadingIndicator.layer?.backgroundColor = NSColor.greenColor().CGColor

Result:

enter image description here

But when I set the background color to white, the background color stays gray (instead of changing to white).

Code:

loadingIndicator.wantsLayer = true
loadingIndicator.layer?.backgroundColor = NSColor.whiteColor().CGColor

Result:

enter image description here

Why does setting the background color to white not work, but green does? How can I correct this issue? I'm on OS X 10.11.4.

EDIT: This apparently only happens when the progress indicator is inside a view that was presented as a popover.

like image 443
Adam Johns Avatar asked Apr 28 '16 21:04

Adam Johns


People also ask

Is it possible to change the background color of the grid?

I think, that apart from background color you should be also able to edit grid: both transparency and color. With both these options this you can fully customize looks & feels of the background. Having some medical eye issues, being able to change the background color or have a dark mode would be really appreciated!

How to change background color to white in an instant?

Fotor's online photo editor lets you change background color to white in an instant. No matter if you want to add a white background to profile pictures or product photos, you’ll just be covered. In addition to this, you can further customize your photos using a variety of editing features.

Should we be able to change the background color?

Changing background color with few defined presets (for example dark one) seems to be more versatile. I think it will be more better if we can change the background into any color, for example: change to black,white,green,blue and more. that will be better because when you use the light color, I nearly cannot see the color

How do I change the color of the transparent background?

After the background has been removed, click on the color box to add a color to the transparent background. Quickly change background color to white, red, blue, black or any other color you like. Once you've added the most befitting color, click on the “Download” button at the top and choose a high-resolution format to download the finished image.


2 Answers

I had same issue when I use NSProgressIndicator inside NSPopover.

My solution was to set appearance to popover like below.

popover.appearance = NSAppearance(named: NSAppearanceNameAqua)
  • Tried on OSX 10.11.5 / Xcode7.3.1
  • Any other name except for NSAppearanceNameVibrantDark also worked

I'm not sure why this happens, but after setting the property I got correct white background color.

Screenshot: white background progress inside popover

like image 57
horimislime Avatar answered Oct 05 '22 22:10

horimislime


I've found a way to fix this. The CALayer of the NSProgressIndicator has a sublayer that is showing the tinted background color you are seeing. Hiding that sublayer will cause no background to ever be shown, and keep the spinner visible.

CALayer *layer = [[self popoverProgressIndicator] layer];
CALayer *backgroundLayer = [[layer sublayers] firstObject];
[backgroundLayer setHidden:YES];

I've only seen this issue when inside of an NSPopover where I was using the solution here to change the background.

like image 45
IMcD23 Avatar answered Oct 05 '22 21:10

IMcD23