In my application, I have created a CALayer
(with a few sublayers - the CALayer is composed of shapes added as sublayers).
I am trying to create a UIImage
that I will be able to upload to a server (I have the code for this).
However, I can't figure out how to add the CALayer
to a UIImage
.
Is this possible? Any advice would be excellent and very appreciated.
Many thanks, Brett
I have created a Swift extension based for this:
The usage:
Swift 3 version with a little bit of error checking for context.
Sounds like you want to render your layer into a UIImage. In that case, the method below should do the trick. Just add this to your view or controller class, or create a category on CALayer.
Todd's answer is correct, however for retina screens there should be a little difference: