Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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!

like image 956
leo Avatar asked Aug 05 '11 10:08

leo


2 Answers

Have you tried the shadowPath property of your layer?

listContainer.layer.shadowPath = [UIBezierPath bezierPathWithRect:listContainer.bounds.CGPath];
like image 117
Ash Furrow Avatar answered Sep 20 '22 04:09

Ash Furrow


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.

like image 22
kgaidis Avatar answered Sep 18 '22 04:09

kgaidis