0

I have a window controller with blue background color

The background color of all children view controllers work fine with blue background just like their parent window controller, except NSTabView of NSTabViewController, which draws with the original gray background

I am not sure why it does not inherit the background color, or why it is not transparent

Anyway, to solve the issue, I tried the following

(1)

I tried editing the CLayer background

tabView.layer?.backgroundColor = NSColor.blue.cgColor

I tried putting that code everywhere, and the only time it worked is when I accessed the CLayer from a tabViewItem inside its viewWillAppear function or viewDidAppear or viewWillLayout, but the problem is that this code does not work until I select another tab... i.e. when the tabViewController is shown at the beginning, the initial view background color is grey, and does not change to blue until I select another tab!

From my understanding, the tabView is drawn after its child viewDidAppear, that's why it overcame the blue color order, and when another tab is selected, the viewDidAppear function is called again changing the color to blue (since the tabView` is already drawn)

(2)

I tried to change drawsBackground value to false

when the tabviewcontroller is shown, the background is just like what its windows is, blue, but as soon as I choose another tab, black residue are left from the previous tabviewitem controls

Black residue from the previous tab controls

any idea how to solve this problem is much appreciated!

Anya Alstreim
  • 133
  • 12
  • Duplicate of [How to change the color of the tab button and the view itself in NSTabView?](https://stackoverflow.com/questions/31419529/how-to-change-the-color-of-the-tab-button-and-the-view-itself-in-nstabview)? – Willeke Sep 08 '17 at 11:55
  • I am asking about the background of the view itself (the blue color you see in the picture), not the tab colors – Anya Alstreim Sep 08 '17 at 19:27
  • The question is also about the view itself. – Willeke Sep 08 '17 at 20:48

2 Answers2

0

I solved this by adding a Custom Box to the initial tab with the required background color, and resized it to the size of the view

In the rest of tab views, I added this line to viewWillAppear function

tabView.layer?.backgroundColor = NSColor.blue.cgColor

The custom box feels like a hack but is the only way around I could come up with

Anya Alstreim
  • 133
  • 12
0

An alternative solution is to place a custom NSBox behind the NSTabView with the correct size and background color. No further code needed, as long as all tabs feature a transparent background.

Ely
  • 8,259
  • 1
  • 54
  • 67