Ios 如何获取uiwebview的内容宽度?
我像这样加载Gif图像Ios 如何获取uiwebview的内容宽度?,ios,uiwebview,gif,Ios,Uiwebview,Gif,我像这样加载Gif图像 [webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; 我想设置uiwebview的中心位置,但我无法获得内容的宽度。请提供帮助。您可以使用javascript中的docume
[webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
我想设置uiwebview的中心位置,但我无法获得内容的宽度。请提供帮助。您可以使用javascript中的
document.height
或document.width
// in init
_WebView.delegate = YourClass; // probably self
- (void) webViewDidFinishLoad:(UIWebView *)webview
{
int w = [[_WebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
_WebView.userInteractionEnabled = w > 200;
}
此处的更多信息:document.width始终返回iphone屏幕的宽度(320),document.height可以正常工作。否,document.width返回页面的宽度。如果您的页面使用iphone的meta标记,则大小为320px。