iphone - 图像无法加载到 iPhone 的 UIWebView 中

标签 iphone ios image uiwebview

我有 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/

相关文章:

ios - 单个应用程序二进制文件如何支持 64 位和 32 位应用程序

ios - 在 Phonegap iOS 应用程序中查看/下载文件

ios - 如何弱引用作为参数传递的函数

ios - 尝试从数组中取出对象,反转它们,然后将它们放回原处

html - 根据当前窗口大小将图像垂直和水平居中

iphone - 如何在 XCode 4.2 中访问 SVN 存储库?

iphone - 使用不推荐使用的UDID的openUDID

image - Julia Flux,神经网络中不同维度的图像

javascript - 使用 Javascript/jQuery 删除图像背景

ios - 如何验证出生日期IOS7