如何在NSTabView中更改选项卡按钮和视图本身的颜色? [英] How to change the color of the tab button and the view itself in NSTabView?

查看:171
本文介绍了如何在NSTabView中更改选项卡按钮和视图本身的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OS X应用程序,并且正在使用NSTabView.我想更改标签(按钮)的背景颜色.当前背景为蓝色,(属性检查器->外观=继承(浅绿色).

I am working on OS X app, and I am using NSTabView. I would like to change the background color of the tab (button). Currently the background is blue, (Attribute Inspector -> Appearance = Inherited (Aqua).

视图本身的背景色也是如此.我将NSTabView子类化,然后在此代码中添加以下内容:

Same is true with the background color of the view itself. I subclass the NSTabView, and I add inside this code:

 CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
 CGContextSetRGBFillColor(context, 241.0/255.0, 252.0/255.0, 255.0/255.0, 1.0);
 CGContextFillRect(context, NSRectToCGRect(dirtyRect));

这确实会更改背景颜色,但还会用背景颜色覆盖选项卡...

which does change the background color, but also cover the tabs with the background color...

对NSTabView自定义的任何帮助将深表感谢.

Any help with customization of the NSTabView will be deeply appreciated.

对于那些将要断定这是重复问题的人...请看一下类似问题的答案中的日期...他们的年龄都在7-8岁左右...

For those who will jump to conclusion that this is duplicate question...please take a look on the dates in the answers on similar questions...they are all old about 7-8 years...

推荐答案

几个小时后,我认为您无法使用NSTabView完成它. 该文档说您不能再这样做了,NSTabView会尊重操作系统选择的主题.

After a couple of hours, I think you can't do it with NSTabView. The documentation says you can no longer do it and NSTabView will respect the theme chosen by the OS instead.

这使我想到了如何绘制自己的NSTabView标签?,我相信您已经看到了.但是,尽管有文档说明,SetImage/ForSegment对我却不起作用.

This led me to How to draw your own NSTabView tabs?, which I'm sure you've seen. But despite the documentation, SetImage/ForSegment did not work for me.

[ NSSegmentedControl颜色似乎找到了一种解决方案,并且SMSegmentView 是另一个.这两种解决方案都是较新的.

[NSSegmentedControl Colors seems to have found one solution, and SMSegmentView is another, although there may be licensing issues. Both these solutions are more recent.

我希望以上内容对您有帮助,祝您好运.

I hope the above will prove useful to you and good luck.

这篇关于如何在NSTabView中更改选项卡按钮和视图本身的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆