us++

user experience, intuitive design

Dynamically size a UIWebview

leave a comment »

Just add the webViewDidFinishLoad delegate method and you can dynamically size a UIWebView based on the content size.

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    webView.frame = frame;

    NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
}

 

Advertisement

Written by eg

November 4, 2010 at 10:40 pm

Posted in iPhone

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.