Тут есть нюанс.
Чтобы написать обработчик нужно написать подкласс NSButton, в котором надо перекрыть метод mouseDown.
Интерфейс:
// // CustomButton.h // #import@interface CustomButton : NSButton @end
Реализация:
//
// CustomButton.m
//
#import "CustomButton.h"
@implementation CustomButton
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"mouseDown");
[super mouseDown:theEvent];
NSLog(@"mouseUp");
}
@end
Результат:
