NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *HTMLData = @"
<h1>Hello this is a test</h1>
<img src="sample.jpg" alt="" width="100" height="100" />";
[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
UIWebView之加载本地网页
最新推荐文章于 2021-07-02 16:17:21 发布
本文介绍了一种在iOS应用中加载包含本地图片资源的HTML内容的方法。通过使用NSBundle获取资源路径,并对路径进行适当的字符串替换处理,使得可以正确地在WebView中显示包含本地图片的HTML页面。
808

被折叠的 条评论
为什么被折叠?



