CALayer shadow with Spread & Size attributes?

I am trying to create a shadow around CALayer. For the effect I'm trying to achieve, I need to have access to the “intensity” of the shadow. Something like the "spread" slider in Photoshop layer styles. I think that the "ShadowRadius" CALayer property is equivalent to the Photoshop "Size" slider.

Any suggestions? Perhaps this is a radial gradient?

+9
source share
2 answers

Set the shadowOffset , shadowOpacity and shadowRadius , and you should get what you are looking for. Try to do this for a shadow project that is directly “under” a 5-pixel blur layer, which with the right color can also 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}; 
+8
source

You can control the “distribution” by setting your own shadowPath property to CALayer.

 CGFloat radius = CGRectGetWidth(view.bounds)/2.0; // this is a sample code for a circle, but you can use any shape you want CGPathRef shadowPathRef = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0 * radius, 2.0 * radius) cornerRadius:radius].CGPath; layer.shadowPath = shadowPathRef; 

If you set the radius to a larger value, the shadow distribution will be larger.

+6
source

All Articles