我有一个按钮,我正在为其添加阴影:
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;
效果很好:
如果我像这样使用阴影路径:
b.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:b.bounds cornerRadius:b.layer.cornerRadius].CGPath;
视网膜设备上的阴影很模糊:
它在非 Retina 设备上很好,如果 shadowRadius
不为零,它似乎可以正常工作。我已经尝试将 contentsScale
和 rasterizationScale
设置为 2,但它不会影响阴影。
还有其他想法吗?
最佳答案
从 iOS 9.0 开始,CALayer
的 contentsScale
属性也会影响 shadowPath
的光栅化比例。换句话说,将层的 contentsScale
设置为屏幕比例将解决您的问题。
关于ios - 为什么在将 shadowRadius 设置为 0 的情况下使用 shadowPath 时,我的 CALayer 阴影在视网膜显示器上变得模糊?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9039892/