2013-06-03 38 views
0

这里是我的代码来加载一个HTML文件,现在在html我想加载图像动态。UIWebView从本地加载html,但从远程使用web服务调用图像

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我想使用web服务调用来填充图像。

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

另外我想用SDWebImage来缓存图片。

回答

0

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

相关问题