我花了一些时间试图弄清楚如何向NSView
. 现在,我正在尝试使用NSShadow
该类来完成此操作。我的代码如下。我正在尝试在NSView
子类的自定义 init 方法中创建阴影。无论我尝试什么,都不会出现阴影。
NSShadow *dropShadow = [[NSShadow alloc] init];
[dropShadow setShadowColor:[NSColor blackColor]];
[self setWantsLayer:YES];
[self setShadow:dropShadow];
编辑
这是我尝试使用CALayer
.
self.layer.shadowOffset = CGSizeMake(10, 10);
self.layer.shadowOpacity = 1.0;
self.layer.shadowRadius = 10.0;
self.layer.shadowPath = [self quartzPathFromBezierPath:[NSBezierPath bezierPathWithRect:frame]];
quartzPathFromBezierPath:
将NSBezierPath
a 转换为CGPath
.