UIButtonにインセットシャドウを設定しようとしています。他のSO投稿のおかげで、これを行うことができました:
UIBezierPath *buttonPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.layer.cornerRadius];
CAShapeLayer* shadowLayer = [CAShapeLayer layer];
//shadowLayer.cornerRadius = 8.0f;
[shadowLayer setOpacity:1];
//[shadowLayer setBackgroundColor:UIColor.redColor.CGColor]; //not working
// Standard shadow stuff
[shadowLayer setShadowOpacity:1.0f];
[shadowLayer setShadowColor:[[UIColor colorWithWhite:1 alpha:1] CGColor]];
[shadowLayer setShadowOffset:CGSizeMake(2.0f, 2.0f)];
[shadowLayer setShadowRadius:5];
// Causes the inner region in this example to NOT be filled.
[shadowLayer setFillRule:kCAFillRuleEvenOdd];
// Create the larger rectangle path.
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectInset(self.bounds, -42.0f, -42.0f));
// Add the inner path so it's subtracted from the outer path.
CGPathAddPath(path, NULL, buttonPath.CGPath);
CGPathCloseSubpath(path);
[shadowLayer setPath:path];
CGPathRelease(path);
[self.layer addSublayer:shadowLayer];
私は素敵な白い内側の影を取得しますが、shadowLayerは黒い不透明な四角形(シャドウパス)を追加します。
試し[shadowLayer setFillColor:UIColor.clearColor.CGColor];
ましたが、影も削除されます。また、何も[shadowLayer setBackgroundColor:UIColor.redColor.CGColor];
しません。
どうすればそれを取り除くことができますか?!