0

下面如何使用代码来实现?类连接到窗口。

在此处输入图像描述

ButtonController *btn=[[ButtonController alloc]init]; 
[btnAbout.cell setTarget:btn]; 

如何实现 mouseEnter 事件?

#import "ButtonController.h"

@implementation ButtonController

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        NSButton *button = (NSButton *)self;
        NSLog(@"%ldsss",(long)button.tag);
    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
}
-(void)mouseEntered:(NSEvent *)theEvent{

    [self mouseEntered:theEvent];
    if (self.tag == 1) {
        NSLog(@"ee");
    }
}
@end

==================================================== =====

==================================================== =====

==================================================== =====

#import "ButtonController.h"

==================================================== =====

ButtonController *btnMax =[[ButtonController alloc]initWithFrame:CGRectMake(15, 0, 14, 14)];
[btnMax setImage:[NSImage imageNamed:@"max"]];
[btnMax setAlternateImage:[NSImage imageNamed:@"maxDown"]];
[[btnMax cell]setHighlightsBy:NSContentsCellMask];
[btnMax setBordered:NO];
[btnMax setTag:2];
[viewGo addSubview:btnMax]; 
4

0 回答 0