「iOS開発」UIWebViewとWKWebViewの使い方

1.UIWebView
func getImage(context: ServiceExecuteContext) -> UIImage {
UIGraphicsBeginImageContextWithOptions(context.fromViewController.webView.bounds.size, true, 0)
context.fromViewController.webView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//let imagRef = CGImageCreateWithImageInRect((image?.CGImage)!, context.fromViewController.webView.bounds)
//let newImage = UIImage.init(CGImage: imagRef!)
//UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
return image!
}

2.WKWebView
func getImage(context: ServiceExecuteContext) -> UIImage {

UIGraphicsBeginImageContextWithOptions(context.fromViewController.webView.bounds.size, true, 0)
for subView: UIView in context.fromViewController.webView.subviews {
subView.drawViewHierarchyInRect(subView.bounds, afterScreenUpdates: true)
}
//UIApplication.sharedApplication().keyWindow?.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//let imagRef = CGImageCreateWithImageInRect((image?.CGImage)!, context.fromViewController.webView.bounds)
//let newImage = UIImage.init(CGImage: imagRef!)

return image!
}

Comments are closed.