【发布时间】:2012-02-05 10:51:15
【问题描述】:
我正在使用此代码在 UIWebView 中显示图像:
-(void)showImageWithLoadRequest{
NSString *path = [[NSBundle mainBundle] pathForResource:@"accent" ofType:@"png"];
NSURL *imageUrl = [NSURL fileURLWithPath:path];
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:imageUrl];
web.scalesPageToFit = YES;
[web loadRequest:imageRequest];
}
问题是当我在模拟器中打开应用程序时,它会显示一个空白的 UIWebView,没有任何图像。
有什么办法可以解决这个问题吗?
我需要从我的资源中加载图像。在我的资源中,我有 2 个图像本地化。可能是问题?
编辑
正如 Seamus 建议的那样,现在我正在使用:
NSString *path = [[NSBundle mainBundle] pathForResource:@"accent" ofType:@"png"];
[myWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
但它仍然显示一个空白的 WebView。有什么想法吗?
【问题讨论】:
标签: objective-c image uiwebview