2010-02-14 59 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

關閉。用它填充,然後將其關閉,並將其關閉。 –

相關問題