最好用这两张图来解释。第一张图片显示了一个尚未悬停的 nsbutton,第二张显示了当我将鼠标悬停在它上面时相同的 nsbutton。
如您所见,无论出于何种原因,NSView 外部贝塞尔路径似乎也绘制在按钮上。该按钮是一个普通的 NSButton 实例,没有子类。
这是我的自定义 NSView :
#import "MyView.h"
@implementation MyView
- (void)drawRect:(NSRect)rect
{
NSBezierPath *path;
path = [NSBezierPath bezierPathWithRect:rect];
[[NSColor redColor] set];
[path fill];
rect.size.width -= 10;
rect.size.height -= 10;
rect.origin.x += 5;
rect.origin.y += 5;
path = [NSBezierPath bezierPathWithRect:rect];
[[NSColor whiteColor] set];
[path fill];
}
- (void)awakeFromNib
{
NSButton *commandButton = [[NSButton alloc] initWithFrame:NSMakeRect(90, 50, 100, 18)];
[commandButton setButtonType:NSMomentaryPushInButton];
[commandButton setBordered:YES];
[commandButton setTitle:@"Test!"];
[commandButton setFont:[NSFont fontWithName:@"LucidaGrande" size:14.0]];
[commandButton setBezelStyle:NSInlineBezelStyle];
[self addSubview:commandButton];
}
@end