I have a button which I'm adding a shadow to like this:
b.backgroundColor = [UIColor colorWithRed:0.820 green:0.878 blue:0.941 alpha:1.000];
b.layer.cornerRadius = 3;
b.layer.shadowOffset = CGSizeMake(2, 2);
b.layer.shadowOpacity = 0.2;
b.layer.shadowRadius = 0;
That works great:
If I use shadow path like so:
b.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:b.bounds cornerRadius:b.layer.cornerRadius].CGPath;
The shadow is blurry on retina devices:
It's fine on non retina devices and seems to work correctly if shadowRadius
isn't zero. I've tried setting contentsScale
and rasterizationScale
to 2 but it doesn't affect the shadow.
Any other ideas?
shadowOffset : the offset of the layer's shadow. The type of this property is CGSize. Width controls the shadow's horizontal offset, and the height controls its vertical offset. The default value of this property is (0.0, -3.0) .
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.
shadowPath controls the shape of the shadow. This defaults to nil , which causes UIKit to render the view offscreen to figure out the shadow shape. shadowRadius controls how blurred the shadow is. This defaults to 3 points.
A number that specifies the amount of blurring around the edges of shadows cast by the light.
As of iOS 9.0 the contentsScale
property of CALayer
will also affect the rasterization scale of shadowPath
. In other words, setting layer's contentsScale
to screen scale will fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With