3

我有一个 Xcode 项目UIWebView。现在我需要将图像从文档目录加载到该 web 视图。我怎样才能做到这一点?

4

1 回答 1

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];
于 2012-09-11T10:18:59.377 回答