2013-02-08 32 views
-1

我在viewDidLoad中写这篇创建,的UIWebView通过IB,并通过代码不定向友好

// 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]; 

这里创建本身不对齐纵向和横向正确,Web视图如果Web视图是,而通过Interface Builder创建,它工作正常。

(不知道什么问题initWithFrame:方法self.view.frame

可能是什么问题呢?

+0

用于反对投票的LOL。有比这更糟糕的问题。 – esh

回答

1

应设置autoresizingMask

webVPrg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

,让视图根据它的父的自动调整尺寸。您可能还需要对您的self.view也这样做。

+0

没错,有时候只是问一个问题会让你看到答案。 :-) – sergio

+0

挂上。我认为autoresizingmask应该应用于Web视图。这不起作用。 – esh

+0

啊,编辑更好。 :) – esh