アプリで複数の.htmlファイルを使用していて、それをWebビューで開きます。htmlページをサムビューとして表示する必要があります。htmlページを画像に変換したり、htmlファイルを表示する他の方法を使用したりすることはできますか。プレビューとして。誰か知っているなら助けてください
			
			2641 次
		
2 に答える
            1        
        
		
-(void) webViewDidFinishLoad:(UIWebView *)webView { 
UIGraphicsBeginImageContext(CGSizeMake(webView.layer.frame.size.width, webView.layer.frame.size.height));
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(CGSizeMake(70,100));
[image drawInRect:CGRectMake(0, 0, 70,100)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//image is now a 70x100 thumbnail. make sure you include CoreGraphics
}
于 2013-01-03T04:05:14.347   に答える
    
    
            0        
        
		
最近、WKWebViewにはもっと便利な方法があります
class WebviewDelegate: NSObject, WKNavigationDelegate {
    var completion: ((UIImage?) -> ())?
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        webView.evaluateJavaScript("document.body.offsetHeight;") { (result, error) in
            if let height = result as? CGFloat {
                let config = WKSnapshotConfiguration()
                config.rect = CGRect(x: 0, y: 0, width: webView.scrollView.contentSize.width, height: height)
                webView.takeSnapshot(with: config) { (image, error) in
                    self.completion?(image)
                }
            }
        }
    }
}
于 2019-11-26T13:47:25.637   に答える