Reputation: 7180
My website has width set to 460px on iPhone 2G, 3G and 4S in portrait mode. It doesn't look good in horizontal mode though. I would say it should have twice as many pixels.
My current viewport tag looks like this:
<meta name="viewport" content="user-scalable=yes, width=460" />
I want 460px in portrait mode.
I want 800px in landscape mode.
This is Apple's documentation but horizontal mode is not mentioned: https://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html
Upvotes: 0
Views: 826
Reputation: 39512
Have you tried using the constant "device-width"?
I've also used the following technique to modify the meta tag after the page has been loaded. You could likely adapt it to modify the meta tag when the device changes between portrait and landscape:
NSString* js =
@"var img = document.getElementsByTagName( 'img' )[0];" \
"var c = 'width=' + img.width + ', height=' + img.height + ', user-scalable=yes, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0';" \
"var h = document.createElement( 'head' ); " \
"var m = document.createElement( 'meta' ); " \
"m.setAttribute( 'name', 'viewport' ); " \
"m.setAttribute( 'content', c ); " \
"h.appendChild( m ); " \
"var html = document.getElementsByTagName( 'html' )[0];" \
"var body = document.getElementsByTagName( 'body' )[0];" \
"html.insertBefore( h, body ); " \
"";
[webView stringByEvaluatingJavaScriptFromString: js ];
Upvotes: 1