我正在创建一个应用程序,需要将页面的一半作为webview,另一半填充其他内容。问题是,当我在UI构建器中布局视图时,它的宽度和高度都是正确的,但实际加载时会占据整个屏幕。
以下是代码:
- (void)loadView
{
// Create a custom view hierarchy.
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *view = [[UIView alloc] initWithFrame:appFrame];
self.view = view;
[view release];
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webView = [[UIWebView alloc] initWithFrame:webFrame];
webView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:webView];
NSString *html = @"<html><head><title>Should be half</title></head><body>I wish the answer were just 42</body></html>";
[webView loadHTMLString:html baseURL:nil];
}