开发者

CGContextSetShadow produces no results

I'm using this code in my UIView subclass to draw a circle with a gradient fill:

- (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);
}

The circle and the gradient draw fine, but I see no shadow. I'm not sure why its not working, because I used the same CGContextSetShadow function in a different view subclass and it worked fine.

NOTE: In the above code, "gradient" is an ivar that was defined previously开发者_如何学Go.


A gradient draw doesn't count as a fill; only fills and strokes get shadows. (You may want to report this as a bug.)

As a workaround, fill the path (with solid black), then turn off the shadow, then draw the gradient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜