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。
你的意思是打開或關閉陰影嗎?我並不完全瞭解這一思路。 – indragie
關閉。用它填充,然後將其關閉,並將其關閉。 –