分两步走:
1.子类化NSWindow,主要是重载了下面这个函数
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag {
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self != nil) {
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
2.子类化NSWindow的view,重载drawRect,其中的圆角半径和背景颜色自己可以调整
- (void)drawRect:(NSRect)dirtyRect
{
[NSGraphicsContext saveGraphicsState];
NSRect rect = [self bounds];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:5 yRadius:5];
[path addClip];
[[NSColor controlColor] set];
NSRectFill(dirtyRect);
[NSGraphicsContext restoreGraphicsState];
[super drawRect:dirtyRect];
}
实现demo效果如下:
