How to determine the content size of a UIWebView?

后端 未结 15 2235
灰色年华
灰色年华 2020-11-22 17:06

I have a UIWebView with different (single page) content. I\'d like to find out the CGSize of the content to resize my parent views appropriately. T

15条回答
  •  盖世英雄少女心
    2020-11-22 17:35

    In Xcode 8 and iOS 10 to determine the height of a web view. you can get height using

    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
        NSLog(@"Webview height is:: %f", height);
    }
    

    OR for Swift

     func webViewDidFinishLoad(aWebView:UIWebView){
            let height: Float = (aWebView.stringByEvaluatingJavaScriptFromString("document.body.scrollHeight")?.toFloat())!
            print("Webview height is::\(height)")
        }
    

提交回复
热议问题