Reputation: 560
I want to be able to save an image to the photos app from a UIWebView
when the user taps and holds on the image.
I've managed to save an image from a UIWebView
when I was programming in objective-c however now as I'm learning swift it seems to be kind of different.
This is how I did it back in Objective-C:
-(IBAction)saveWeb:(id)sender
{
UIGraphicsBeginImageContext(webview.frame.size);
[self.webview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil,nil,nil);
}
Upvotes: 0
Views: 2968
Reputation: 2148
The snippet you have right now is more towards taking a screen shot of the web page.
You can combine gesture recognizers and Javascript to get an image at a give point in a HTML page..
Have a look at https://stackoverflow.com/a/5607694/4236572 . You may want to implement something like that..
Upvotes: 1