我有 UIWebView,我想在其中加载图像,但它不显示图像,我正在使用以下代码
pdfView.hidden=NO;
webView.hidden=NO;
pdfView.backgroundColor=[UIColor clearColor];
doneButton = [[UIBarButtonItem alloc]initWithTitle:@" Done " style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonClick)];
self.navigationItem.leftBarButtonItem =doneButton;
webView.backgroundColor=[UIColor clearColor];
NSLog(@"File Name is %@",fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"];
NSURL *url = [NSURL fileURLWithPath:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
有什么方法可以加载来自此 webView 中的服务器的 fileName 中的图像,谢谢
最佳答案
我可以采用的另一种方法是动态 html 页面并将其加载到 UIWebView 中:
NSString *imageUrlString = @"your url ";
NSString *yourText = @"Some text here";
NSString *htmlString = [NSString stringWithFormat:@"<img src='%@'/><br><b>%@</b>", imageUrlString, yourText];
[myWebView loadHTMLString:htmlString baseURL:nil];
关于iphone - 图像无法加载到 iPhone 的 UIWebView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17210909/