简体   繁体   English

NSTabView 背景色

[英]NSTabView Background Color

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所有子视图控制器的背景颜色都可以在蓝色背景下正常工作,就像它们的父窗口控制器一样,除了 NSTabViewController 的 NSTabView,它使用原始的灰色背景绘制

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) (1)

I tried editing the CLayer background我尝试编辑 CLayer 背景

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... ie 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!我尝试将该代码放在任何地方,唯一一次起作用的是当我从viewWillAppear函数或viewDidAppearviewWillLayout的 tabViewItem 访问 CLayer 时,但问题是此代码在我选择另一个选项卡之前不起作用......即当 tabViewController 在开头显示时,初始视图背景颜色为灰色,并且在我选择另一个选项卡之前不会更改为蓝色!

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)从我的理解中, tabView是其子后得出viewDidAppear ,这就是为什么它克服了蓝色顺序,并且选择另一个选项卡时,该viewDidAppear函数被调用再次改变颜色为蓝色(因为tabView`已经绘制)

(2) (2)

I tried to change drawsBackground value to false我试图将drawsBackground值更改为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当显示tabviewcontroller时,背景就像它的窗口一样,蓝色,但是一旦我选择另一个选项卡,之前的tabviewitem控件就会留下黑色残留物

上一个选项卡控件的黑色残留物

any idea how to solve this problem is much appreciated!非常感谢如何解决这个问题的任何想法!

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在其余的选项卡视图中,我将此行添加到viewWillAppear函数

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

The custom box feels like a hack but is the only way around I could come up with自定义框感觉就像一个黑客,但我能想出的唯一方法

An alternative solution is to place a custom NSBox behind the NSTabView with the correct size and background color.另一种解决方案是将一个自定义NSBox后面NSTabView具有正确大小和背景颜色。 No further code needed, as long as all tabs feature a transparent background.不需要更多代码,只要所有选项卡都具有透明背景即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM