WebView 加载本地HTML 文件 提示找不到该文件
答案:2 悬赏:40
解决时间 2021-02-08 04:54
- 提问者网友:℡她的他i☆
- 2021-02-07 12:27
WebView 加载本地HTML 文件 提示找不到该文件
最佳答案
- 二级知识专家网友:末路丶一枝花
- 2021-02-07 13:55
这个file:是?
全部回答
- 1楼网友:寂寞的炫耀
- 2021-02-07 14:36
uiwebview加载工程本地网页与本地图片
- (void)viewdidload
{
[super viewdidload];
nsstring *filepath = [[nsbundle mainbundle]pathforresource:@"1" oftype:@"html"];
nsstring *htmlstring = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:nil];
mywebview = [[uiwebview alloc] initwithframe:self.view.bounds];
mywebview.delegate = self;
[self.view addsubview:mywebview];
[mywebview loadhtmlstring:htmlstring baseurl:[nsurl urlwithstring:filepath]];
}
-(void)webviewdidfinishload:(uiwebview *)webview
{
nsstring *imagepath = [[nsbundle mainbundle] resourcepath];
imagepath = [imagepath stringbyreplacingoccurrencesofstring:@"/" withstring:@"//"];
imagepath = [imagepath stringbyreplacingoccurrencesofstring:@" " withstring:@"%20"];
nsstring * js = [nsstring stringwithformat:@"document.images[0].src='file:/%@//%@'",imagepath,@"icon-04.png"];
[mywebview stringbyevaluatingjavascriptfromstring:js];
nsstring *path = [mywebview stringbyevaluatingjavascriptfromstring:@"document.images[0].src"];
nslog(@"path:%@", path);
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯