我有一个带有圆角和阴影的自定义 UILabel。我正在使用 CALayer 上的属性来实现这一点。接下来,我尝试使用 renderInContext: 将其保存为 UIImage。圆角保持不变,但出现黑色背景和松散的阴影。
关于将 UILabel 渲染为图像但保持阴影和圆角的任何想法?
这是我用来呈现标签的代码:
UIGraphicsBeginImageContextWithOptions(label.bounds.size, YES, 0);
[label.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();