代码之家  ›  专栏  ›  技术社区  ›  Atma

如何在iPhone上居中显示UIWebView的内容

  •  3
  • Atma  · 技术社区  · 16 年前

    UIWebView . 它默认加载在左上角。我希望它初始化在 UIWebView

    有人知道怎么做吗?

    2 回复  |  直到 13 年前
        1
  •  6
  •   rickharrison    16 年前

    如果地图图像是页面中唯一的东西,它是否包装在html页面中?如果它至少包装在body标记中,则可以执行以下操作:

    NSString *bodyStyle = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';";
    NSString *mapStyle = @"document.getElementById('mapid').style.margin = 'auto';";
    
    [webView stringByEvaluatingJavaScriptFromString:bodyStyle];
    [webView stringByEvaluatingJavaScriptFromString:mapStyle];
    

    让我知道你的html是如何准确的结构,然后我可以提供一些更多的信息,如果必要的话。

        2
  •  2
  •   Venk    13 年前

    center-aligned div标签。

    <body>
    <div align="center">
    <!-- Your map here -->
    </div>
    </body>
    

    UIWebView . 它不需要任何javascript调用。但是,如果您希望在网页加载后按需注入样式表更新,则需要上述解决方案。