如何获取uiwebview的内容宽度?

时间:2013-02-14 08:09:23

标签: ios uiwebview gif

我像这样加载Gif图像

[webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

我想设置uiwebview的中心位置,但我无法获得内容的宽度。请帮忙。

1 个答案:

答案 0 :(得分:0)

您可以使用javascript中的document.heightdocument.width

// in init
_WebView.delegate = YourClass; // probably self

- (void) webViewDidFinishLoad:(UIWebView *)webview
{
  int w = [[_WebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
  _WebView.userInteractionEnabled = w > 200;
}

此处有更多信息:https://www.albertopasca.it/whiletrue/objective-c-get-uiwebview-html-page-size/