如何在iPhone上集中UIWebView的内容

Atm*_*tma 3 iphone cocoa-touch center uiwebview

我有一张地图图片UIWebView.它默认加载在左上角.我希望它在中心初始化UIWebView.

有谁知道如何做到这一点?

谢谢!

ric*_*son 6

如果地图图像是页面中唯一的内容,它是否包含在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];
Run Code Online (Sandbox Code Playgroud)

让我知道您的HTML是如何构造的,然后我可以在必要时提供更多信息.