Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer shadow with Spread & Size attributes?

i'm struggling creating a drop shadow around a CALayer. For the effect i'm trying to achieve i need to have access to the "intensity" of the shadow. Somehow like the "spread" slider in Photoshop's Layer Styles. I think the "ShadowRadius" property of CALayer is equivalent to Photoshop's "Size" slider.

Any suggestions? Is maybe a radial gradient an option?

like image 747
bijan Avatar asked Nov 30 '11 00:11

bijan


People also ask

What is shadow radius?

shadowRadius : the blur radius used to render the layer's shadow. A value of zero creates a hard-edged shadow that exactly matches the shape of the view. A larger value creates a soft-edged shadow that looks more natural. The default value of this property is 3.0 .

What is shadow opacity in Swift?

shadowColor sets the color of the shadow, and needs to be a CGColor . shadowOpacity sets how transparent the shadow is, where 0 is invisible and 1 is as strong as possible. shadowOffset sets how far away from the view the shadow should be, to give a 3D offset effect. shadowRadius sets how wide the shadow should be.

What is the purpose of IOS shadow?

The layer's shadow uses several elements: shadowOffset , shadowColor , shadowOpacity , and shadowRadius . Each element changes the respective appearance. You can offset the shadow differently to change the direction the shadow is cast - how far from the layer and in which direction.

What is shadow radius in Swift?

The blur radius (in points) used to render the layer's shadow.


1 Answers

Set the layer's shadowOffset,shadowOpacity, and shadowRadius and you should have what you are looking for. Try this for a shadow project directly "underneath" the layer with a blur of 5 pixels, which with the right color, could also make it look like a glow:

CALayer *layer = myView.layer;
layer.shadowOpacity = 0.50;
layer.shadowRadius = 5.0;
layer.shadowOffset = (CGSize){.width=0.0,.height=0.0};
like image 123
gschandler Avatar answered Sep 18 '22 22:09

gschandler