How to add an image as html and load it to webview in iPhone sdk?
I am implementing a webview based application, in that I tried to load an image but it is not coming as expected. I don't know what is the problem. The following is my code that I tried. Please suggest me if I did any thing wrong.
NSString *returnString = @"";
returnString = [returnString stringByReplacingOccurrencesOfString:@"<html><body>" withString:@"<body> <p>Hello Sekhar"];
r开发者_C百科eturnString = [returnString stringByAppendingString:@"<img src='tutorial/images/bg1.png'"];
returnString = [returnString stringByAppendingString:@"alt='footer'"];
returnString = [returnString stringByAppendingString:@"align='middle' width='140' height='32' />"];
returnString = [returnString stringByAppendingString:@"</p></body></html>"];
[myWebView loadHTMLString:returnString baseURL:[NSURL URLWithString:@"http:www.google.com"]];
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];
NSLog(@"webview %@", bundlePath);
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
NSString * html = [NSString stringWithContentsOfFile:filePath encoding:NSStringEncodingConversionAllowLossy error:nil];
if (htmlData) {
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:bundleBaseURL];
}
used the search function once: load-image-in-web-view-from-a-html-file
精彩评论