简体   繁体   English

CALayer将阴影投射到每个子图层,如何删除?

[英]CALayer drops shadow to each sublayer, how to remove?

I've got a UIView container with a table view in it, whose cells contain images and buttons. 我有一个带有表视图的UIView容器,其单元格包含图像和按钮。

I want to add a shadow to the outter-most container but when I do, I found shadows are also added to all the images and buttons. 我想给最外面的容器添加一个阴影,但是当我这样做时,我发现阴影也被添加到所有图像和按钮中。 How can I only add shadow to the layer itself without its sublayers? 如何在没有子层的情况下只为图层本身添加阴影?

code: 码:

listContainer.layer.shadowColor = [UIColor blackColor].CGColor;
listContainer.layer.shadowOffset = CGSizeMake(3, 0);
listContainer.layer.shadowOpacity = .8;
listContainer.layer.borderColor = [UIColor blackColor].CGColor;

Thanks! 谢谢!

您是否尝试过图层的shadowPath属性?

listContainer.layer.shadowPath = [UIBezierPath bezierPathWithRect:listContainer.bounds.CGPath];

I had this problem once and the issue was that the layers background color was transparent. 我有一次这个问题,问题是图层背景颜色是透明的。

So if you have a UIView, or CALayer, and you are trying to set shadows on it, make sure that there is a background color to prevent shadows from being applied to the sublayers. 因此,如果您有UIView或CALayer,并且您正尝试在其上设置阴影,请确保存在背景颜色以防止阴影应用于子图层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM