Iphone CGContextSetShadow不产生任何结果

Iphone CGContextSetShadow不产生任何结果,iphone,cocoa,cocoa-touch,core-graphics,cgcontext,Iphone,Cocoa,Cocoa Touch,Core Graphics,Cgcontext,我在UIView子类中使用以下代码绘制带有渐变填充的圆: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadow (context, CGSizeMake(4,4), 5); CGContextBeginPath (context); CGContextAddEllipseInRect(context, CGRe

我在UIView子类中使用以下代码绘制带有渐变填充的圆:

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetShadow (context, CGSizeMake(4,4), 5);
    CGContextBeginPath (context);
    CGContextAddEllipseInRect(context, CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 38, 38));
    CGContextClosePath (context);
    CGContextClip (context);
    CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMinX(self.bounds), CGRectGetMaxX(self.bounds)), CGPointMake(CGRectGetMaxX(self.bounds), CGRectGetMinY(self.bounds)), 0);
}
圆圈和渐变画得很好,但我看不到阴影。我不确定为什么它不工作,因为我在不同的视图子类中使用了相同的CGContextSetShadow函数,它工作得很好


注意:在上述代码中,“渐变”是先前定义的ivar。

渐变绘制不算作填充;只有填充和笔划才能获得阴影。(您可能想这样做。)


作为一种解决方法,先填充路径(使用纯黑色),然后关闭阴影,然后绘制渐变。

您的意思是打开还是关闭阴影?我不太明白你的想法。关掉。填充时启用它,然后禁用它并在禁用它的情况下绘制渐变。