我试图在圆角视图中制作一个透明的NSWindow。透明窗口中的圆角NSView
我想要一个透明窗口的圆角视图。
这是它看起来像现在:(见角的小圆点)
下面是与(在一个NSView的drawRect集)设置为10px圆角半径另一个例子:
我使用代码从这款苹果样本:https://developer.apple.com/library/mac/#samplecode/RoundTransparentWindow/Introduction/Intro.html
具体这个方法在我的NSWindow的子类:
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag {
// Using NSBorderlessWindowMask results in a window without a title bar.
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self != nil) {
// Start with no transparency for all drawing into the window
[self setAlphaValue:1.0];
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
这在我的NSView子类:
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor redColor] set];
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath appendBezierPathWithRoundedRect:dirtyRect xRadius:3 yRadius:3];
[thePath fill];
}
谁能告诉我什么,我在这里失踪?
谢谢。
没有尝试,但使用QuartzCore,并设置cornerRadius(在CALayer)? – Larme 2013-02-21 17:08:08