I'm using a UIWebView with text in it. When the iPhone is rotated to landscape, text doesn't fill the now wider UIWebView width. I'm using P (paragraph) tags, which should not affect content filling landscape's width. The line breaks that are visible in portrait remain the same in landscape. In Interface Builder, I haven't changed anything. In the IB Inspector, Web View Size has all solid bars under AutoSizing, which means it should fill to the landscape width right?
Iphone – Filling width in (iPhone) UIWebView landscape orientation
interface-builderiphonelandscapeuiwebview
Related Solutions
It's certainly possible to develop on a Windows machine, in fact, my first application was exclusively developed on the old Dell Precision I had at the time :)
There are three routes;
- Install OSx86 (aka iATKOS / Kalyway) on a second partition/disk and dual boot.
- Run Mac OS X Server under VMWare (Mac OS X 10.7 (Lion) onwards, read the update below).
- Use Delphi XE4 and the macincloud service. This is a commercial toolset, but the component and lib support is growing.
The first route requires modifying (or using a pre-modified) image of Leopard that can be installed on a regular PC. This is not as hard as you would think, although your success/effort ratio will depend upon how closely the hardware in your PC matches that in Mac hardware - e.g. if you're running a Core 2 Duo on an Intel Motherboard, with an NVidia graphics card you are laughing. If you're running an AMD machine or something without SSE3 it gets a little more involved.
If you purchase (or already own) a version of Leopard then this is a gray area since the Leopard EULA states you may only run it on an "Apple Labeled" machine. As many point out if you stick an Apple sticker on your PC you're probably covered.
The second option is more costly. The EULA for the workstation version of Leopard prevents it from being run under emulation and as a result, there's no support in VMWare for this. Leopard server, however, CAN be run under emulation and can be used for desktop purposes. Leopard server and VMWare are expensive, however.
If you're interested in option 1) I would suggest starting at Insanelymac and reading the OSx86 sections.
I do think you should consider whether the time you will invest is going to be worth the money you will save though. It was for me because I enjoy tinkering with this type of stuff and I started during the early iPhone betas, months before their App Store became available.
Alternatively, you could pick up a low-spec Mac Mini from eBay. You don't need much horsepower to run the SDK and you can always sell it on later if you decide to stop development or buy a better Mac.
Update: You cannot create a Mac OS X Client virtual machine for OS X 10.6 and earlier. Apple does not allow these Client OSes to be virtualized. With Mac OS X 10.7 (Lion) onwards, Apple has changed its licensing agreement in regards to virtualization. Source: VMWare KnowledgeBase
I wrote this function to set the viewport width as a UIWebView is resized. You can easily adapt it to set a viewport property other than width.
-(NSString *) setViewportWidth:(CGFloat)inWidth {
NSString *result = [_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"(function ( inWidth ) { "
"var result = ''; "
"var viewport = null; "
"var content = 'width = ' + inWidth; "
"var document_head = document.getElementsByTagName('head')[0]; "
"var child = document_head.firstChild; "
"while ( child ) { "
"if ( null == viewport && child.nodeType == 1 && child.nodeName == 'META' && child.getAttribute( 'name' ) == 'viewport' ) { "
"viewport = child; "
"content = child.getAttribute( 'content' ); "
"if ( content.search( /width\\s=\\s[^,]+/ ) < 0 ) { "
"content = 'width = ' + inWidth + ', ' + content; "
"} else { "
"content = content.replace( /width\\s=\\s[^,]+/ , 'width = ' + inWidth ); "
"} "
"} "
"child = child.nextSibling; "
"} "
"if ( null != content ) { "
"child = document.createElement( 'meta' ); "
"child.setAttribute( 'name' , 'viewport' ); "
"child.setAttribute( 'content' , content ); "
"if ( null == viewport ) { "
"document_head.appendChild( child ); "
"result = 'append viewport ' + content; "
"} else { "
"document_head.replaceChild( child , viewport ); "
"result = 'replace viewport ' + content; "
"} "
"} "
"return result; "
"})( %d )" , (int)inWidth]];
return result;
}
Best Answer
Here is a tweak though not a good thing to do, and something should be handled by apple itself
As you've noticed that things workfine when WebView is initialized in portrait and then you turn it to landscape. So.. what you can do is always initialize your webview with portrait bounds, add a selector which calls back after 2~3 seconds and sets the frame of webView according to your requirement.
Now as the contents started loading when the frame size of your webview were according to portrait (say 320,460) so converting your webview to landscape will automatically adjust your web view if you have this line in your code
Below is the snippet of code