首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景色NSTabView

背景色NSTabView
EN

Stack Overflow用户
提问于 2011-11-11 06:56:34
回答 3查看 3.9K关注 0票数 3

正如在其他地方所讨论的,NSTabView没有一个setBackgroundColor方法和子类NSTabView,并且使用drawRect来控制它不再工作--因为它没有绘制前10%的位置,这个位正好在分段控制按钮的下方。

现在,我对我不得不做的大量工作感到惊讶,你看

https://github.com/dirkx/CustomizableTabView/blob/master/CustomizableTabView/CustomizableTabView.m

  • 代码

我想知道我是不是走错路了。以及如何做得更好&更简单:

  • NSSegmentStyleTexturedSquare似乎给了我一个半透明的分段控制。这意味着我需要做额外的工作来隐藏任何边框线(第240行,第253行)。

代码语言:javascript
复制
- 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 ?

  • --我发现我需要的颜色--比如NSColor windowBackgroundColour --没有设置成任何有用的(即透明的)--所以现在我对它们进行硬编码(第87、94行)。

代码语言:javascript
复制
- Is there a better way to do this ?

  • 我发现我需要一船毛茸茸的方法来保持同步(第128、134行等)。

代码语言:javascript
复制
- can this be avoided ?

  • ,我发现模仿重新标度时的聪明意味着我需要时刻关注分段控制框,并删除/调整它的大小。即使如此,它也不如原来的

那么好。

代码语言:javascript
复制
- is there a better way to do this than line 157 -- i.e. hear about resizing ? Rather than do it all the time ?

当焦点从窗口移除时,

  • segementControl会褪色--这与真正的McCoy不同。

代码语言:javascript
复制
- can that easily be prevented ? is there a cheap way to track this ? 

  • 还是说这是错误的方法--我应该专注于这里的一个透明的漏洞--让NSTabViewItem画一个背景吗?但是在任何情况下--那么我仍然对分段COntrol框存在问题--或者说有一种方法可以使其再次成为默认的。

代码语言:javascript
复制
- 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.

反馈很受欢迎--因为对于这样简单的事情来说,这感觉很不理想--非常感谢。用于黑客/分叉github代码的Brownie点:) :)作为一行运行的代码,需要超过1000个单词。

Dw。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-01-09 16:58:20

PSMTabBarControl可能是您的最佳解决方案。我已经创建了几个自定义选项卡视图,但可可并不能很好地使用此控件。PSMTabBarControl已被更新,以支持Xcode 4. https://github.com/ciaran/psmtabbarcontrol

票数 1
EN

Stack Overflow用户

发布于 2015-06-01 21:29:48

您是否尝试过设置其基础CALayer的背景色?(如果还没有,则通过设置wantsLayer =YES将其设置为层背景视图。)

票数 0
EN

Stack Overflow用户

发布于 2015-10-03 08:49:07

如果您的情况可以容忍某些脆弱性,那么一个非常简单和快捷的方法是将NSTabView子类划分为子类,并手动调整项子视图的框架。这使每个项目都有一个无缝的黄色背景:

代码语言:javascript
复制
- (void)drawRect:(NSRect)dirtyRect {
    static const NSRect offsetRect = (NSRect) { -2, -16, 4, 18 };

    NSRect rect = self.contentRect;

    rect.origin.x += offsetRect.origin.x;
    rect.origin.y += offsetRect.origin.y;
    rect.size.width += offsetRect.size.width;
    rect.size.height += offsetRect.size.height;

    [[NSColor yellowColor] set];
    NSRectFill(rect);

    [super drawRect:dirtyRect];
}

NSTabView指标的未来更改显然是一个问题,因此您自己承担风险吧!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8090641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档