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関数を別のビューサブクラスで使用し、正常に機能したため、なぜ機能しないのかわかりません。
注:上記のコードでは、「gradient」は以前に定義されたivarです。