Iphone – Filling width in (iPhone) UIWebView landscape orientation

interface-builderiphonelandscapeuiwebview

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?

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

[webViewObjet_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

Below is the snippet of code

- (id) initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        webViewObjet_ = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
        .....
    }
}

- (void) webViewDidStartLoad:(UIWebView *)webView
{
    .....       
    [self performSelector:@selector(chuss) withObject:nil afterDelay:3];
    // call the function chuss after 3 second
}

- (void) chuss
{
    webViewObjet_.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [webViewObjet setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}