Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
Is it possible to resize a UIWebView via code?

The reason I want to do this is because I have a ToolBar with navigation-buttons that appears each time the webview is touched, and disappears when the user clicks a hide-button.

The problem is that the toolbar is displayed on top of the webview, thus sometimes making stuff on the webpage untouchable.

The perfect solution would be the ability to resize the webview when the toolbar appears and disappears, but so far I have not found any solution.

Any ideas would be welcome.
 
You might want the toolbar to disappear by itself after a period of time.

If not then the web view has a frame like every other view. Just adjust the frame to make the web view bigger and smaller when needed.
 
Ah, yes, forgot about that - adjusting the frame should work (using setFrame)!

Thanks a lot :)
 
This code works perfectly for my needs.

Code:
    // Resize:  Webview height small (toolbar opened)
    CGRect newFrame = webView.frame;
    newFrame.size = CGSizeMake(self.webView.frame.size.width, self.toolBar.frame.origin.y);
    webView.frame = newFrame;

    // Resize:  Webview height Full (toolbar closed)
    CGRect newFrame = webView.frame;
    newFrame.size = CGSizeMake(self.webView.frame.size.width, (self.toolBar.frame.origin.y + self.toolBar.frame.size.height) );    
    webView.frame = newFrame;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.