Note that there are some explanatory texts on larger screens.

plurals
  1. PONSPushOnPushOffButton Not Staying "Pushed In"
    primarykey
    data
    text
    <p>I'm trying to add a button to a view programmatically and I'd like it to stay "pushed in" when clicked, until it is clicked again. From what I've read it seems like the button to use for this would be <code>NSPushOnPushOffButton</code>. Here's Apple's discription for it:</p> <blockquote> <p>The first click both highlights and causes the button to be “pushed in” if the button is bordered; a second click returns it to its normal state. This option is called “Push On Push Off” in Interface Builder’s Button Inspector.</p> </blockquote> <p>It wasn't working in my program so I made a SSCCE, which I'll include below. My problem is the button isn't staying in when clicked, but rather popping back out like a normal button. I'm not sure if I'm missing something about how this button is supposed to perform or if I'm simply implementing it incorrectly (This is the first time I've tried to do a UI programmatically), but other button types such as <code>NSToggleButton</code> work so unless there is something special about <code>NSPushOnPushOffButton</code> I don't see where I went wrong. if someone could suggest a better solution or explain where I went wrong that would be great. Thanks!</p> <pre><code>#import "AppDelegate.h" @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSRect buttonFrame = NSMakeRect(0,0,200,200); NSButton *button = [[NSButton alloc]initWithFrame:buttonFrame]; [self.window.contentView addSubview:button]; [button setButtonType:NSPushOnPushOffButton]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload