Can renderInContext: support angular radius and shadow?

I have a custom UILabel with round corners and a shadow. I use properties on CALayer to achieve this. Then I try to save this as a UIImage using renderInContext :. Round corners are supported, but a black background appears and the shadow is lost.

Rendered image

Any thoughts on rendering UILabel as an image, but keeping shadow and rounded corners?

Here is the code I use to render the label:

UIGraphicsBeginImageContextWithOptions(label.bounds.size, YES, 0);
[label.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+5
source share
1 answer

You can get rounded corners by changing the second argument to "NO" in UIGraphicsBeginImageContextWithOptions.

+6
source

All Articles