将文档目录图像加载到Web视图中

时间:2012-09-11 10:00:09

标签: iphone uiwebview uiimage

我有一个带UIWebView的Xcode项目。现在我需要将文档目录中的图像加载到该webview。我怎么能实现这个目标呢?

1 个答案:

答案 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];