如何在iOS中纵向和横向居中显示webview的内容? [英] How do I center the contents of a webview in iOS vertically and horizontally?

查看:490
本文介绍了如何在iOS中纵向和横向居中显示webview的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用谷歌搜索了一下,我似乎无法找到任何对我有意义的东西。我需要纵向和横向中心webview的内容。我已经能够得到水平线了:

I have googled quite a bit and I can't seem to find anything that makes sense to me. I need to center the contents of a webview both vertically and horizontally. I have been able to get the horizontal to work with this:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *bodyStyle = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';";
    [self.webView stringByEvaluatingJavaScriptFromString:bodyStyle];
}

但我在垂直方面找不到任何东西。有任何想法吗?任何帮助将不胜感激。

But I can't find anything on vertical. Any ideas? Any help would be appreciated.

推荐答案

试试这样,

NSString *bodyStyleVertical = @"document.getElementsByTagName('body')[0].style.verticalAlign = 'middle';";
NSString *bodyStyleHorizontal = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';";
NSString *mapStyle = @"document.getElementById('mapid').style.margin = 'auto';";

[webView stringByEvaluatingJavaScriptFromString:bodyStyleVertical];
[webView stringByEvaluatingJavaScriptFromString:bodyStyleHorizontal];
[webView stringByEvaluatingJavaScriptFromString:mapStyle];

希望它会帮助你.....

Hope it will helps you.....

这篇关于如何在iOS中纵向和横向居中显示webview的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆