开发者

Display picture in UIWebView store locally (Iphone)

In My Iphone app I display a local HTML file into a UIWebView. Inside the html code I try to display a local picture who is store in the repertory 'Ressourc开发者_高级运维e'. I want to know what is the path, I can't point to my picture.

Thanks,


Assuming your image is named MyImage.png and is in your app bundle's Resources folder:

NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"MyImage" ofType: @"png"];


there is no need to put the path into the html-page for each image manually.

Simply reference the images without a path, e.g. and store the html-file and the images in the resource folder. Then use the following code to set the content of the UIWebView:

NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"help-en" ofType:@"html"];
NSMutableString *html    = [[NSMutableString alloc] initWithContentsOfFile: filePathString]; 
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
[webView loadHTMLString:html baseURL:aURL];


NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"png"];
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:aURL];
[self.webView loadRequest:req];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜