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?
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.