带背景颜色的 NSTabView
正如其他地方所讨论的,NSTabView 没有 setBackgroundColor 方法,并且子类化 NSTabView 并使用 drawRect 来控制它不再起作用 - 因为它不会绘制顶部 10%,即分段控制按钮正下方的部分。
现在,我对解决这个问题必须做的大量工作感到有点惊讶;请参阅
我想知道我是否走错了路。以及如何做得更好&更简单:
NSSegmentStyleTexturedSquare 似乎为我提供了一个半透明的分段控件。这意味着我需要做额外的工作来隐藏任何边框线(第 240、253 行)。
有更好的方法吗?即否定其透明度?
或者有什么方法可以使用实际/原始分段选择按钮?
我发现我需要的颜色 - 例如 [NSColor windowBackgroundColour] 没有设置为任何有用的颜色(即透明的) - 所以现在我对它们进行硬编码(第 87、94 行)。
- 有更好的方法吗?
我发现我需要大量蓬松的方法来保持同步(第 128、134 行等)。
- 这种情况可以避免吗?
我发现模仿重新缩放的巧妙方法意味着我需要时刻关注分段控制框并删除/调整其大小。即便如此 - 它还是不如原来的
- 有没有比第 157 行更好的方法——即听说调整大小?而不是一直这样做?
当焦点从窗口中移开时,segmentControl 会变暗 - 与真正的 McCoy 不同。
- 这很容易避免吗?有没有一种便宜的方法来跟踪这个?
或者这是错误的方法 - 我应该只关注这里的透明孔 - 并让 NSTabViewItem 绘制背景吗?但无论如何 - 那么我仍然遇到分段控制框的问题 - 或者有没有办法让它再次成为默认值。
- 尝试此操作时 - 我被困在以“真实”窗口背景颜色绘制的顶部 20-30 个像素上 - 这是“透明” - 因此颜色不会一直延伸到顶部或后面分段栏一直到边框 - 但停在分段控件底部下方约 8 个像素处。
感谢反馈 - 因为对于如此简单的事情来说,这感觉很遥远/次优 - 多谢。 Brownie 指出 hack/fork github 代码:) :) :) 因为一行运行代码说了一千多个字。
深度。
As discussed elsewhere, NSTabView does not have a setBackgroundColor method and subclassing NSTabView and using an drawRect to control it does no longer work - as it does not paint the top 10%, the bit just below the segmented control button.
Now I am a bit surprised by the amounts of work arounds I had to do solving this; see
- code: https://github.com/dirkx/CustomizableTabView/blob/master/CustomizableTabView/CustomizableTabView.m
and am wondering if i went down the wrong path. And how to do this better & simpler:
The NSSegmentStyleTexturedSquare seems to yield me a semi-transparent segmented Control. Which means I need to do extra work to hide any bezel lines (line 240, 253).
is there a better way to do this ? I.e. negate its transparency ?
or is there a way I can use the actual/original segmented choise button ?
I find that the colours I need - like the [NSColor windowBackgroundColour] are not set to anything useful (i.e. that one is transparent) -- so right now I hardcode them (lines 87, 94).
- Is there a better way to do this ?
I find I need a boatload of fluffy methods to keep things in sync ( line 128, 134, etc).
- can this be avoided ?
I find that mimicking the cleverness on rescaling means I need to keep a constant eye on the segemented Control box and remove/resize it. And even then - it is not quite as good as the original
- is there a better way to do this than line 157 -- i.e. hear about resizing ? Rather than do it all the time ?
The segementControl fades dark when focus is removed from the window - unlike the real McCoy.
- can that easily be prevented ? is there a cheap way to track this ?
Or is this the wrong approach - and should I focus on just a transparent hole here - and let the NSTabViewItem draw a background ? But in any case - then I still have the issue with the Segemented COntrol box - or is there than a way to make that be the default again.
- when trying this - I get stuck on the top 20-30 pixels being drawn in the 'real' windows background colour - which is 'transparent' - and hence the colour will not run all the way to the top or behind the segment bar and up to the bezel - but instead stop some 8 pixels below the bottom of the segment controls.
Feedback appreciated - as this feels so far off/suboptimal for such a simple things --
Thanks a lot. Brownie points for hacking/forking the github code :) :) :) As a line of running code says more than a thousand words.
Dw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PMTabBarControl 可能是最适合您的解决方法。我创建了几个自定义选项卡视图,但可可不能很好地使用此控件。 PSMTabBarControl 已更新为支持 Xcode 4。 https://github.com/ciaran/psmtabbarcontrol
PSMTabBarControl is probably the best workaround for you. I have created several custom tab views, but cocoa does not play well with this control. PSMTabBarControl has been updated to support Xcode 4. https://github.com/ciaran/psmtabbarcontrol
您是否尝试过设置其底层 CALayer 的背景颜色? (如果还没有,请通过设置 WantLayer = YES 将其设为图层支持视图。)
Have you tried setting the background color of its underlying CALayer? (Make it a layer-backed view, if it isn't already, by setting wantsLayer = YES.)
如果您的情况可以容忍一些脆弱性,一个非常简单且快速的方法是子类化
NSTabView
并手动调整项目子视图的框架。这为每个项目提供了无缝的黄色背景:NSTabView
指标的未来变化显然会成为一个问题,因此请自行承担风险!If your situation can tolerate some fragility, a very simple and quick approach is to subclass
NSTabView
and manually adjust the frame of the item subviews. This gives each item a seamless yellow background:A future change in the metrics of
NSTabView
would obviously be a problem so proceed at your own risk!