开发者社区> 问答> 正文

使用UIWebView显示html文件

创建了一个UIWebView,使用HTML文件来显示一些内容。但是运行之后,没有显示内容而是显示了HTML全部编码。不知道应该怎么解决?

UIWebView *ingradients= [[UIWebView alloc]init];
    [ingradients setFrame:CGRectMake(10, 170, 300, 300)];
    [ingradients loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"htmlfile" ofType:@"html"]isDirectory:NO]]];
    ingradients.delegate=self;
    [self.view addSubview:ingradients];

htmlfile.html 内容

<html>
<body>
<p><strong>Ingredients</strong></p>
</body>
</html>

结果没有显示成粗体的 Ingredients ,而是将代码都全部显示出来了。

展开
收起
爵霸 2016-03-24 11:31:17 1887 0
1 条回答
写回答
取消 提交回答
  • 测试了你的代码是正确的,问题出在你的htmlfile.html文件里。请用类似UE等工具打开确保里面的内容是:

    <html>
    <body>
    <p><strong>Ingredients</strong></p>
    </body>
    </html>

    或者直接用Chrome打开htmlfile.html再查看源码。

    2019-07-17 19:12:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《零基础HTML入门教程》 立即下载
天猫 HTML5 互动技术实践 立即下载
天猫HTML5互动技术实践 立即下载