1
votes

I have created a vertical NSStackView that contains two NSView subclasses (they are just NSViews that draw a background color). I have the stack view set to detach hidden views. I have set one of the views to be hidden.

Neither view hides in the stack view.

To make sure I'm not insane, I also set up two of the same NSViews next to each other, hiding one. Sure enough, one does hide.

The stack view's distribution is set to Fill Proportionally (not that that seems to matter).

In IB the behavior seems correct; one of the views hides.

I must be missing something incredibly obvious here, right?

enter image description here

In case it is relevant, the NSView subclass: #import "ViewWithBackgroundColor.h"

@implementation ViewWithBackgroundColor

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    [self.backgroundColor set];
    [NSBezierPath fillRect:dirtyRect];
    if(self.bottomBorderColor != nil) {
        NSBezierPath *linePath = [[NSBezierPath alloc] init];
        [self.bottomBorderColor set];
        linePath.lineWidth = 2.0;
        [linePath moveToPoint:NSMakePoint(0, 0)];
        [linePath lineToPoint:NSMakePoint(dirtyRect.size.width, 0)];
        [linePath stroke];
    }

}

- (NSColor *) backgroundColor {
    if (_backgroundColor) {
        return _backgroundColor;
    } else {
        return [NSColor clearColor];
    }
}

@end
1

1 Answers

4
votes

This looks like an issue with IB and stack view (please file a bug report if you already haven't).

To workaround it you could either:

  • Don't hide the button in IB, and set it to be hidden at runtime.

or

  • Uncheck the 'Detaches Hidden Views' stack view property in IB (visible in your screen shot), and set it at runtime with -[NSStackView setDetachesHiddenViews:].