2013-02-08 35 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