NSOutlineView vs Mojave : Background color is not the background color?

I would like to have the grid color in an NSOutlineView to be the color of the background of the oultine view. The idea is that the grid should be invisible in most cases but not when the row background color is not the default one.


So I use:


myOutlineView.gridColor=myOutlineView.backgroundColor; // where the background color of the outline view is set to Default in the xib.


I had some concerns about the color not being dynamic for the grid color when switching between light and dark aqua. But it actually works fine.


The problem I have is that the grid color is not exactly the color of the background in Dark Aqua. So instead of the grid being invisible, it's a bit visible.


Question:


If the color of the background used to render an outline view is not exactly the value of backgroundColor, then what is it supposed to be? And why would it be different?

Accepted Reply

Hi packagesdev,


If your outline view is using the default background color (

+controlBackgroundColor
), then in Dark Mode it will automatically use a desktop-tinted material for its background. Because this material subtly changes based on the predominant color of the desktop picture, it won't exactly match any drawing done directly with
+controlBackgroundColor
, including these grid lines.


For the case you've described, I think one of the cleanest options would be to disable the default grid drawing using the outline view's

gridStyleMask
property, and then subclass NSTableRowView to draw gridlines based on your special criteria.

Replies

Just a hint. Would the alpha be a bit different ?

Hi packagesdev,


If your outline view is using the default background color (

+controlBackgroundColor
), then in Dark Mode it will automatically use a desktop-tinted material for its background. Because this material subtly changes based on the predominant color of the desktop picture, it won't exactly match any drawing done directly with
+controlBackgroundColor
, including these grid lines.


For the case you've described, I think one of the cleanest options would be to disable the default grid drawing using the outline view's

gridStyleMask
property, and then subclass NSTableRowView to draw gridlines based on your special criteria.

Thanks for the info.


The solution I implemented was to:


- disable the grid drawing as recommended.

- increase the height of the rows by 1 pixel.

- offset the contents of the rows by 1 pixel to the top.


This way I don't have to figure out which color to use and this "draws" a horizontal grid with the background color.

I had to change my NSOutLineView's View appearance to "Inherited (System, ....". Then it just worked and followed the Light/Dark modes. It had been set to "Vibrant" in my case.