解决方法
编辑:事实证明,如果你的目标是OS X Lion或更高版本,这种行为会更容易 – 只需调用[sheet setOpaque:NO]即可启用圆角.
这种行为很容易重现.将工作表初始化为透明无边框窗口:
self.sheet = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,300,300) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered | NSTitledWindowMask defer:YES]; [self.sheet setOpaque:NO]; [self.sheet setBackgroundColor:[NSColor clearColor]];
[[self.sheet contentView] addSubview:[[IFWindowView alloc] initWithFrame:[[self.sheet contentView] frame]]];
该自定义视图应如下所示:
#define RADIUS 5.0 NSBezierPath *bezierPath = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(self.bounds.origin.x,self.bounds.origin.y + RADIUS,self.bounds.size.width,self.bounds.size.height) xRadius:RADIUS yRadius:RADIUS]; [[NSColor windowBackgroundColor] set]; // In production,use the appropriate color with alpha for transparency. [bezierPath fill];
以下是一些示例代码,用于演示此操作:http://d.pr/l9DB