我在 NSView 的自定义类中有这个,当我使用 drawMyRec IBAction 按下按钮时,我想更改 NSRect 的颜色,但这不起作用,谁能帮忙?
#import "myView.h"
@implementation myView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
RectColor = [[NSColor blackColor] init];
}
return self;
}
- (IBAction)drawMyRec:(id)sender;
{
NSLog(@"pressed");
RectColor = [[NSColor blueColor] init];
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)dirtyRect
{
NSRectFill(dirtyRect);
[RectColor set];
}
@end