NSTabView with background color

前端 未结 3 1272
小鲜肉
小鲜肉 2021-01-03 09:11

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 no

相关标签:
3条回答
  • 2021-01-03 09:35

    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

    0 讨论(0)
  • 2021-01-03 09:35

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

    0 讨论(0)
  • 2021-01-03 09:36

    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:

    - (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];
    }
    

    A future change in the metrics of NSTabView would obviously be a problem so proceed at your own risk!

    0 讨论(0)
提交回复
热议问题