2010-02-14 57 views
3

我用我的UIView子类这段代码画圆用渐变填充:CGContextSetShadow产生任何结果

- (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函数,并且它工作正常。

注意:在上面的代码中,“gradient”是以前定义的ivar。

回答

3

渐变绘制不算作填充;只填充和中风得到阴影。 (您可能要report this as a bug。)

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

+0

你的意思是打开或关闭阴影吗?我并不完全了解这一思路。 – indragie

+0

关闭。用它填充,然后将其关闭,并将其关闭。 –

相关问题