Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top