Question

I am writing this in viewDidLoad,

// Programmatically creating uiwebview. 
UIWebView *webVPrg = [[UIWebView alloc] initWithFrame:self.view.frame];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *urlReq = [[NSMutableURLRequest alloc] initWithURL:url];
[self.view addSubview:webVPrg];
[webVPrg loadRequest:urlReq];

The web view created here does not align itself to portrait and landscape orientations properly, whereas if the web view is created through Interface Builder, it works fine.

(Not sure if something wrong with initWithFrame:self.view.frame)

What could be the problem?

Était-ce utile?

La solution

You should set the autoresizingMask:

webVPrg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

to make the view automatically adapt its size according to its superview's. You will possibly need to do the same with your self.view as well.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top