Convert UIWebview contents to a UIImage

前端 未结 2 740
北荒
北荒 2020-12-04 20:42

I am using a UIWebView to display HTML formatted text. I am not loading a webpage, just supplying a string of HTML to the UIWebView.

Now I want to animate this UIWe

2条回答
  •  死守一世寂寞
    2020-12-04 21:06

    UIGraphicsBeginImageContext(webview.bounds.size);
    [webview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    You might run into issues if the webview dimensions are large because the webview uses a CATiledLayer that doesn't draw everything for memory reasons.

    The image will include transparency

提交回复
热议问题