1.加载后台返回的页面
[_webView loadHTMLString:_goodsModel.descriptionstr baseURL:[NSURL URLWithString:[LEUserManager imageURL]]];
[LEUserManager imageURL]是统一的获取图片前缀
2.加载本地h5页面
先把html文件放到工程中,filePath为其路径
UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
webView.scalesPageToFit = YES;
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"测试" ofType:@"html" inDirectory:@"protocol2"];
NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
[self.view addSubview:webView];
另外区分一个 加载轮播图跳转的网页(如百度)时:
_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49)];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",_topImageMode.linkUrl]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request ];
[self.view addSubview:_webView];
网友评论