【问题标题】:How to get content width of uiwebview?如何获取uiwebview的内容宽度?
【发布时间】:2013-01-29 23:47:03
【问题描述】:

我像这样加载 Gif 图像

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

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

【问题讨论】:

    标签: ios uiwebview gif


    【解决方案1】:

    您可以在 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/

    【讨论】:

    • document.width 总是返回 iphone 屏幕的宽度 (320),document.height 工作正常。
    • 不,document.width 返回页面的宽度。如果您的页面使用 iphone 的元标记,则大小为 320 像素。
    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 2016-09-11
    相关资源
    最近更新 更多