Search code examples
cocoansbox

How to disable NSBox from code


I put several controls (button,textfield,...) in a NSBox. is it possible to disable NSBox that user can't access controls (means can't click on button or write in textfield)?

how about nsview ?


Solution

  • Or, if you have a custom NSBox, you can override NSView's -hitTest: (conditionally)

    - (NSView *)hitTest:(NSPoint)aPoint {
        if (!enabled) return nil;
        else return [super hitTest:aPoint];
    }
    

    To stop the window from sending events to all your subviews.

    To provide visual feedback, conditionally drawing some sort of overlay in the custom NSBox's -drawRect method would work.