Im trying to render a view to an image,
Ive been following this example:
Render a full UIImageView to a bitmap image
as well as others.
My problem is that when I get to the line
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
I get a warning stating that “-instance method ‘-renderInContex:’ not found
Every example I see that renders a view to an image uses this line. So why is my example not working?
Heres the full code:
-(void)RenderViewToImage:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *bitmapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPaths objectAtIndex:0];
[UIImagePNGRepresentation(bitmapImage) writeToFile:[documentsDir stringByAppendingString:@"num1.png"] atomically:YES];
}
Make sure you link against the QuartzCore framework.
Make sure you import the following header: