我有一个NSBezierPath,我想在路径内绘制插入阴影(类似于Photoshop).
反正有没有这样做?另外,我知道你可以使用-stroke路径,但是你可以在路径中划线(类似于Photoshop中的Stroke Inside)吗?
static NSImage * graydient = nil;
if (!graydient) {
graydient = [[NSImage alloc] initWithSize: NSMakeSize(22, 22)];
[graydient lockFocus];
NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: clr(@"#262729"), 0.0f, clr(@"#37383a"), 0.43f, clr(@"#37383a"), 1.0f, nil];
[gradient drawInRect: NSMakeRect(0, 4.179, 22, 13.578) angle: 90.0f];
[gradient release];
[graydient unlockFocus];
}
NSColor * gcolor = [NSColor colorWithPatternImage: graydient];
[gcolor set];
NSShadow * shadow = [NSShadow new];
[shadow setShadowColor: [NSColor colorWithDeviceWhite: 1.0f alpha: 1.0f]];
[shadow setShadowBlurRadius: 0.0f];
[shadow setShadowOffset: …Run Code Online (Sandbox Code Playgroud) 我有一个带有文本字段和边框按钮的窗口.它没有边框和透明,但问题在任何窗口都会重现.
该窗口的内容视图在IB中设置为绘制窗口背景的自定义类.
这是代码:
- (void)drawRect:(NSRect)dirtyRect
{
[NSGraphicsContext saveGraphicsState];
float cornerRadius = 10;
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:cornerRadius yRadius:cornerRadius];
[path setClip];
NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations:
[NSColor colorWithCalibratedRed:0.96f green:0.96f blue:0.96f alpha:1.00f], 0.0f,
[NSColor colorWithCalibratedRed:0.84f green:0.84f blue:0.84f alpha:1.00f], 1.0f,
nil];
[gradient drawInRect:self.bounds angle:270];
[NSGraphicsContext restoreGraphicsState];
}
Run Code Online (Sandbox Code Playgroud)
它会导致一些非常奇怪的文物,比如消失的对象或文本字段的背景变为窗口:

这是怎么回事?我试图隔离它,我一直在玩这个"图形上下文状态保存"的东西(我不确定我是否理解正确),但问题仍然存在.
我有XCode 4.4,SDK是10.7(我的操作系统也是如此),部署目标是10.6.这可能没关系,但过去我一直在做类似的事情,我从未遇到过这样的奇怪问题.