我在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];
此处创建的Web视图无法正确对齐纵向和横向,而如果Web视图通过Interface Builder 创建,则可以正常工作。
(不确定 initWithFrame:self.view.frame 是否有问题)
可能是什么问题?
答案 0 :(得分:1)
您应该设置autoresizingMask
:
webVPrg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
使视图根据其超级视图自动调整其大小。您也可能需要对self.view
执行相同操作。