Search code examples
objective-cnsbutton

NSButton highlight on mouse over and toggle state via click


In Xcode, there is an 'In My Scope' button which highlights when you mouse over and stays highlighted until its 'unclicked'.

I can reproduce this via interface builder with the following:

Xcode 'In My Scope'

But I can't get this working via Code. This is what I've come up with:

scopeButton = [NSButton buttonWithTitle: @"In My Scope"
                                                   target: self
                                                   action: @selector(onScopeButton:)];
[scopeButton setButtonType: NSButtonTypeMomentaryLight];
scopeButton.translatesAutoresizingMaskIntoConstraints = NO;
scopeButton.bezelStyle = NSBezelStyleRecessed;
scopeButton.bordered = YES;

And as far as I can tell, that matches the interface builder settings, but it works no where near the same. Any suggestions as to how I can get this to work via code?


Solution

  • Replace

    scopeButton.bordered = YES;
    

    by

    scopeButton.showsBorderOnlyWhileMouseInside = YES;