Re: Layers and shadows. Is it possible to have a layer with a shadow and no background color?


Alex Zavatone
 

But that’s exactly what I want. I want to add a shadow to an item with no opacity. I am specifying the shadow path as a bezier path so that I can overlay an additional shadow over a UIView.

We have a UIView. Let’s say it’s a rect. We have a need for multiple shadows on said aforementioned UIView. We would like to create a layer so that we can add a shadow to this layer and then add that very same layer to the UIView. Insert it, actually. Therefore, an empty layer would be ideal.

Right now, I am copying the layer and adding the shadow to that rect in a shadow adding method. This will suck if the shadow has partially transparent sections and the transparency of the layers add up, making those sections darker.

Simply put, you can’t add more than one shadow to a UIView. If you do, the new shadow overwrites the previous one. We have a need to add 3. This is why I’m going to these steps.

Thanks.
Alex Zavatone

On Jun 24, 2021, at 9:26 AM, Jeremy Hughes via groups.io <moon.rabbit@...> wrote:

On 24 Jun 2021, at 14:28, Alex Zavatone via groups.io <zav@...> wrote:

But it’s odd, since I set the shadow opacity to 1, which is 100%.
Sure — but it doesn’t matter how opaque the shadow is. An object with zero opacity won’t have a shadow (in real life or in computer graphics).

Imagine some opaque text on a transparent background (e.g. polythene in real life). The text will cast a shadow but the transparent background (polythene) won’t.

Jeremy





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