我有一个带UIWebView
的Xcode项目。现在我需要将文档目录中的图像加载到该webview。我怎么能实现这个目标呢?
答案 0 :(得分:7)
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"/imageName.png"]];
[myWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",imagePath] baseURL:nil];