元视口标记没有';在iOS UIWebView中似乎不起作用
为什么下面的方法不起作用?其目的是使元视口标记没有';在iOS UIWebView中似乎不起作用,ios,css,uiwebview,viewport,meta,Ios,Css,Uiwebview,Viewport,Meta,为什么下面的方法不起作用?其目的是使div的宽度为iphone屏幕的1/2。在桌面浏览器(如OSX Safari和Chrome)中,它可以正常工作 index.html: <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1" /> </head> <body> <br><br>&
div
的宽度为iphone屏幕的1/2。在桌面浏览器(如OSX Safari和Chrome)中,它可以正常工作
index.html:
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<br><br><br>
<div style="background-color: red; width: 50%">hello iphone</div>
</body></html>
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
}
iphone模拟器:
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<br><br><br>
<div style="background-color: red; width: 50%">hello iphone</div>
</body></html>
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
}
在xcode 7.0.1+iOS9中似乎有
元视口
;然而,建议的变通方法,如初始比例=1.0001
和收缩到适合=否
对我来说并不奏效。我试过使用模拟器和物理设备
这是迄今为止唯一有效的解决方案:
<html>
<body>
<br><br><br>
<div id="red-div" style="background-color: red;">hello iphone</div>
<script>
document.getElementById('red-div').style.width = screen.width/2 + 'px';
</script>
</body>
</html>
你好,iphone
document.getElementById('red-div')。style.width=screen.width/2+'px';