Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can renderInContext: maintain corner radius and shadows?

I have a custom UILabel with round corners and a drop shadow. I'm using the properties on CALayer to achieve this. Next, I'm trying to save this as a UIImage using renderInContext:. The round corners are maintained, but a black background appears and a loose the drop shadow.

Rendered Image

Any thoughts on rendering the UILabel as an image but maintaining the shadow and rounded corners?

Here's the code I'm using to render the label:

UIGraphicsBeginImageContextWithOptions(label.bounds.size, YES, 0);
[label.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
like image 548
Quentamia Avatar asked May 10 '12 16:05

Quentamia


Video Answer


1 Answers

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

like image 146
Prometheus Avatar answered Sep 23 '22 08:09

Prometheus