UIBezierPath を使用して UIView のカスタム シャドウを作成しようとしています。カスタムパスを描くのに苦労していますが、斜めの影にしたいです。
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOpacity = 0.7f;
self.layer.shadowOffset = CGSizeMake(-5.0f, 10.0f);
self.layer.shadowRadius = 5.0f;
self.layer.masksToBounds = NO;
CGFloat shadowDepth = 20.0;
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0, 0.0)];
[path addLineToPoint:CGPointMake(self.bounds.size.width, shadowDepth)];
[path stroke];
self.layer.shadowPath = path.CGPath;
影は現れません。影のパスをビューの境界の周りに設定するだけで、影が正しく表示されます。したがって、ベジエ パスを間違って描画しているに違いありません。何か案は?
これは機能します:
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];