我遇到了 UIWebView 的问题。我想在 UIWebView 中渲染我自己的 html 代码。
如果我使用下面的代码,它工作正常。
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *path = [thisBundle pathForResource:@"foo" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:@"foo.html" baseURL:baseURL];
我想用下面的代码渲染 html。但这不起作用。 foo.html 包含与 NSString* 完全相同的内容。有什么提示吗?提前致谢。 =)
NSString* one = @"<html><head><title></title></head><body><img src=\"image.jpg\"/></body></html>";
[self.webView loadHTMLString:one baseURL:nil] ;
我使用这个完美运行的代码:
NSString* htmlContent = @"<html><head><title></title></head><body><img src='image.jpg' /></body></html>";
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
请确保 image.jpg 包含在您的项目中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)