美文网首页
iOS加载h5页面

iOS加载h5页面

作者: lllaa | 来源:发表于2017-11-21 15:46 被阅读6次

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];

相关文章

网友评论

      本文标题:iOS加载h5页面

      本文链接:https://www.haomeiwen.com/subject/ydjwvxtx.html