0

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).

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...

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

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...

user2417624
  • 653
  • 10
  • 32
  • Have you looked into [creating an appearance file](http://stackoverflow.com/questions/19780577/how-can-i-make-an-appearance-file-for-nsappearance)? – rob mayoff Oct 31 '15 at 00:00

2 Answers2

2

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.

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 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.

Community
  • 1
  • 1
Roy Falk
  • 1,685
  • 3
  • 19
  • 45
  • I had small hopes that someone somewhere had found solution for this, but I am loosing the hope now. On the end, I will add my own custom buttons which will change custom views on click I guess. At least I can have the design that I want...I will have much more work to do, but I can't find any other solution...Thanks for trying to help anyway. – user2417624 Nov 01 '15 at 10:50
  • Saved myself some time and used a NSBox and a NSSegmentedControl and everything looks as it should on dark theme os. NSTabView is buggy in my opinion, it is completely black, while on white theme is semi transparent, doesn't make any sense since no other component does this. I'm using it in a popover, probably it even behaves different on normal windows. – Cristi Băluță Apr 23 '18 at 05:25
-3

the following code is the one that i use for doing that, working right now with iOS 9

[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:(44/255.00) green:(71/255.00) blue:(95/255.00) alpha:1]]; //TAB BAR TINT COLOR
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:(249/255.00) green:(153/255.00) blue:(44/255.00) alpha:1]];//BUTTON TINT COLOR
[[UITabBar appearance] setTranslucent:NO];
[[UITabBar appearance] setAlpha:1];

And the result is something like this

Image from the tab