ludo
ludo

Reputation: 1479

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 'Ressource'. I want to know what is the path, I can't point to my picture.

Thanks,

Upvotes: 1

Views: 3361

Answers (3)

Ashvin
Ashvin

Reputation: 9027

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

Upvotes: 0

Stiefel
Stiefel

Reputation: 2793

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

Upvotes: 0

Costique
Costique

Reputation: 23722

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

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

Upvotes: 2

Related Questions