這在iOS中算是蠻常用的東西,不過我每次用完就忘了,在這Memo一下。
其中因為WebView放在ViewController內,所以使用"self.view.frame"來取得CGRect
UIWebView *myWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"URL Here!"]];
[myWeb loadRequest:request];
[self.view addSubview:myWeb];
如果需要在NavigationController內直接push出一個ViewController請使用以下方式
UIViewController *myViewController = [[UIViewController alloc] init];
UIWebView *myWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, myViewController.view.frame.size.width, myViewController.view.frame.size.height)];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"URL Here!"]];
[myWeb loadRequest:request];
[myViewController.view addSubview:myWeb];
[self.navigationController pushViewController:myViewController animated:YES];
相關連結
iOS Developer Library
iOS Developer Library - UIWebView Class Reference
iOS UIWebView loadRequest
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言