UIWebView使用Web服务调用从本地加载html,但从远程加载图像

时间:2013-06-03 07:21:58

标签: ios uiwebview

这是我加载html文件的代码,现在在html中我想加载动态图像。

NSString *path = [[NSBundle mainBundle] pathForResource:@"Myfile" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:path];

NSString *resourceURL = [[NSBundle mainBundle] resourcePath];
resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",resourceURL]];

[self.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];

这就是我的html的样子。这里代替image.png我想使用webservice调用来填写图像。

<html>
    <body>
        <img src="image.png" />
    </body>
</html>

另外,我想使用SDWebImage来缓存图像。

1 个答案:

答案 0 :(得分:0)

使用正则表达式预处理HTML字符串,该表达式将“img src ...”文本转换为完整的URL。

相关问题