Cocoa button creation looks pressed programmatically

I have some key events that also correspond to buttons. What property / method should I set / call the button to look depressed (change state?), Say, half a second?

+5
source share
2 answers

As I solved this, I set NSButton to "Push On Push Off" and then used the following code in my event handler:

NSButton *button = [self.superview viewWithTag:event.keyCode];
if (button != nil && button.state == NSOffState) {
    [button performClick:event];
    [button performSelector:@selector(performClick:) withObject:event afterDelay:0.5];
}

A button will be highlighted here, as if the user clicked on it, and then clicked it again after half a second.

+1
source

, -setHighlighted: . -setNeedsDisplay: , , , , , , , , .

( , , .)

+1

All Articles