user3786609
user3786609

Reputation: 211

Objectivec set shadow to parent view

I want to set shadow to parent view. But I want child views to remain the same.

What I do now is

parentView.layer.shadowRadius = 0.8;
parentView.layer.shadowOpacity = 0.3;
parentView.layer.shadowOffset = CGSizeMake(1.0, 1.4);

However, if I do this, the child views are also changed. Is there a way to set the shadow but keep the child views the same.

Thank you

Upvotes: 0

Views: 1481

Answers (1)

NKorotkov
NKorotkov

Reputation: 3681

Is your parentView by any chance transparent? I've set up a simple project and used your code. I've changed some values to see a shadow a little better. This is how it looks:

enter image description here

As you can see - no shadow on the subview. parentView's background color is set to white. When I set it to clear color this is what happens. I added the border to prove that parentView is still there:

enter image description here

Apple Docs prove this:

Figure A-7 shows several different versions of the same sample layer with a red shadow applied. The left and middle versions include a background color so the shadow appears only around the border of the layer. However, the version on the right does not include a background color. In this case, the shadow is applied to the layer’s content, border, and sublayers.

enter image description here

Upvotes: 14

Related Questions