![](/img/trans.png)
[英]displaying image in the center of the screen in iphone webview using css, html
[英]Image not displaying from local html on iPhone webview
我在下面用一个来自参考资料的图像调用一个infoPage.html,并在html中引用为img src =“eye.png”,文本正确显示但我无法加载图像(只显示?),任何建议.. 。
- (void)viewDidLoad {
[super viewDidLoad];
CGRect webRect = CGRectMake(15,40,300,450);
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
myWebView.delegate = self;
myWebView.scalesPageToFit = NO;
NSString *htmlPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"infoPage.html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath];
[myWebView loadHTMLString:htmlContent baseURL:nil];
//stop webview from scrolling
[[[myWebView subviews] lastObject] setScrollingEnabled:NO];
[myWebView loadHTMLString:htmlContent baseURL:nil];
[self.view addSubview:myWebView];
[myWebView release];
}
您需要使用[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]]而不是-loadHTML,以便它知道从哪里提取图像。 或者,您可以将路径作为baseURL:参数传递。
而不是baseURL:nil,尝试baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.