相关疑难解决方法(0)

使用-setClip方法重新绘制自定义视图上的插入NSShadow

我有奇怪的问题,与这个问题的答案有关:

绘制插入NSShadow和插入笔划

我将此代码用于自定义视图的drawRect方法.我有这个:

- (void)drawRect:(NSRect)rect
{   
    // Create and fill the shown path
    NSBezierPath *path = [NSBezierPath 
                          bezierPathWithRoundedRect:[self bounds] 
                          xRadius:4.0f 
                          yRadius:4.0f];

    [[NSColor colorWithCalibratedWhite:0.8f alpha:0.2f] set];

    [path fill];

    // Save the graphics state for shadow
    [NSGraphicsContext saveGraphicsState];

    // Set the shown path as the clip
    [path setClip];

    // Create and stroke the shadow
    NSShadow * shadow = [[[NSShadow alloc] init] autorelease];
    [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0f alpha:0.8f]];
    [shadow setShadowBlurRadius:2.0];
    [shadow set];
    [path stroke];

    // Restore the graphics state
    [NSGraphicsContext restoreGraphicsState];

    if ( highlight …
Run Code Online (Sandbox Code Playgroud)

cocoa drawing nsbezierpath nsshadow

2
推荐指数
1
解决办法
1472
查看次数

标签 统计

cocoa ×1

drawing ×1

nsbezierpath ×1

nsshadow ×1