views:

453

answers:

2

Helllo, i would like to show Content in the UIWebView, which i have added to the Project. for example an image. I know how to set a text in the UIWebView, but i would like to add images or a video which i have added to the project

best regards,

+2  A: 

Ok, I am assuming you are using loadHTMLString to set the HTML on your UIWebView.

So to reference images that are stored in your App bundle, you just need to get the right path to put in your img tag. So get the path string:

NSString * imgPath = [[NSBundle mainBundle] pathForResource:nameOfImage ofType:@"jpg"];

Format some HTML with an image tag:

NSString * html = NSString [[[NSString alloc] initWithFormat:@"<img src=\"file://%@\"/>", imgPath] autorelease];

Then set your HTML on the web view:

[self.webView loadHTMLString:html baseURL:nil];

You just need to add the images to your app resources (nameOfImage in the code above) and it will work fine.

Cannonade
To get the file URL, use NSURL: http://developer.apple.com/iphone/library/documentation/cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/clm/NSURL/fileURLWithPath:
Sixten Otto
Key phrase : "which i have added to the Project"
Cannonade
A: 

Similar question answered here.

Ramin