如果我使用故事板添加uiwebview,它的效果很好。但是以编程方式添加的网页浏览不会滚动。
self.webview=[[UIWebView alloc] init];
path=[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
[self.webview setFrame:CGRectMake(-200, 0, 200, 300)];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
[self.view addSubview:self.webview];
答案 0 :(得分:0)
UIWebview
使用以下代码以编程方式添加到View中:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width,600)];
[webview setBackgroundColor:[UIColor redColor]];
NSString *url=@"http://www.facebook.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
[self.view addSubview:webview];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end