怎么用WebView加载本地html

 我来答
千锋教育
2016-09-03 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
1、可以是用loadData,这种方法需要先将html文件读取出来,以字符串传入loadData,可以展示页面,但是不会引用css、js等文件。
2、使用loadUrl,不过需要注意,这里因为是使用本地数据,所以传入的url需要做些处理,例如:
  a、如果html文件存于assets:则加前缀:file:///android_asset/
  b、如果html文件存于sdcard:则加前缀:content://com.android.htmlfileprovider/sdcard/
    注意:content前缀可能导致异常,直接使用file:///sdcard/ or file:/sdcard也可以
匿名用户
2016-09-03
展开全部
1、可以是用loadData,这种方法需要先将html文件读取出来,以字符串传入loadData,可以展示页面,但是不会引用css、js等文件。
2、使用loadUrl,不过需要注意,这里因为是使用本地数据,所以传入的url需要做些处理,例如:
  a、如果html文件存于assets:则加前缀:file:///android_asset/
  b、如果html文件存于sdcard:则加前缀:content://com.android.htmlfileprovider/sdcard/
    注意:content前缀可能导致异常,直接使用file:///sdcard/ or file:/sdcard也可以
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
就烦条0o
2016-09-03 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46483
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
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);
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式