How to get a webpage to fit to the iPhone screen in Xcode

Go To StackoverFlow.com

0

I am trying to get a webpage to fit to the iPhone screen using Xcode, but at the bottom of the screen I put a textbox to allow a user to enter in a username. This means that the webview box is a little bit smaller than using the full screen. I know how to make webpage fit to the full screen, but how do you fit it in a frame smaller than the full iPhone screen?

2012-04-03 19:42
by teambold
Can you not just drag the bottom size handle up to make it shorter? Or set the height in IB to be less? I don't understand the question. Are you trying to make the web view shorter so that you can see the UILabel - jmstone617 2012-04-03 22:30


0

Start with a UIView in IB that is the full size of the screen and then put your web view and text fields inside it. You should then be able to resize the web view.

2012-04-03 19:47
by Phillip Mills


0

Init with frame:

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, width, height)];
2012-04-03 19:47
by jbook
I used this line, but got an error message- Use of undeclared identifier 'x'; is this correct code for Xcode 4.3 - teambold 2012-04-03 20:46
You need to actually set x, y, width, and height. He just gave you the methods to use. You need to actually fill them out.. - jmstone617 2012-04-03 22:28


0

Try this:

CGFloat x = 0;
CGFloat y = 0;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height - 30;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, width, height)];
[self.view addSubview:webView]; // Add the webview to the main view

This will make the height of the webView 30 points less than the main view you are adding it to.

2012-04-03 20:52
by Paul Hunter
When I used this I just got a blank white screen other thank the username text field and submit button. Here is the code I have under the viewDidLoad method: NSString *website =@"http://www.gamoda.org"; NSLog(@"%@", website);
NSURL *url = [NSURL URLWithString:website]; NSURLRequest *requestURL =[NSURLRequest requestWithURL:url]; CGFloat x = 0; CGFloat y = 0; CGFloat width = self.view.frame.size.width; CGFloat height = self.view.frame.size.height - 100; UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, width, height)] - teambold 2012-04-03 22:07
I added one more line to my example that adds the webview to your main view - Paul Hunter 2012-04-04 12:22
that worked! thank you - teambold 2012-04-05 01:00
Ads