问题描述
- webView内容水平和垂直都居中
-
需要水平和垂直居中webView的内容,我可以这样实现水平居中- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *bodyStyle = @"document.getElementsByTagName('body')[0].style.textAlign = 'center';"; [self.webView stringByEvaluatingJavaScriptFromString:bodyStyle]; }
但是不知道怎么实现垂直居中?
解决方案
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];
试试看
时间: 2024-11-03 22:12:21