문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top