Re: Adding multiple shadows to a UIView in either Objective-C or Swift


Alex Zavatone
 

Well, it sure is an important detail.  If no color is added or if you use a clear color, you get no shadow.  

I did find a sort of a solution though and this works as long as you don’t have a transparency on the image.  

Duplicate the CALayer.

But that’s the problem?  How? 

Through NSKeyedArchiver or CAReplicatorLayer.

CALayer *layer1;
CALayer *layer2;

// Set up layer1's specifics.

layer2 = [NSKeyedUnarchiver unarchivedObjectOfClass:[CALayer class]
                                                            fromData:[NSKeyedArchiver archivedDataWithRootObject:layer1 requiringSecureCoding:NO error:nil] error:nil];

Two shadows on one UIView with 2 layers.  Testing now with PNG and SVG images.

This also works.

Cheers and if anyone wants the code when I’m done, I’ll happily share it.

Alex Zavatone



On Jun 16, 2021, at 10:40 AM, Carl Hoefs <newslists@...> wrote:

In past code, I've used the behavior that layers will render a shadow whose strength is in accord with the opacity of the fill color. 0 opacity (clearColor) gives no shadow at all.

I think you may be fighting the frameworks here...

-Carl


On Jun 16, 2021, at 8:33 AM, Alex Zavatone via groups.io <zav@...> wrote:

Apparently, layers do now render shadows at all if the layer is of clearColor.








Join cocoa@apple-dev.groups.io to automatically receive all group messages.