【问题标题】:How to add an image as html and load it to webview in iPhone sdk?如何将图像添加为 html 并将其加载到 iPhone sdk 中的 webview?
【发布时间】:2010-12-21 11:03:59
【问题描述】:

我正在实现一个基于 webview 的应用程序,因为我尝试加载图像但它没有按预期出现。我不知道是什么问题。以下是我尝试过的代码。如果我做错了什么,请建议我。

  NSString *returnString = @"";

returnString = [returnString stringByReplacingOccurrencesOfString:@"<html><body>" withString:@"<body> <p>Hello Sekhar"];
returnString = [returnString stringByAppendingString:@"<img src='tutorial/images/bg1.png'"];   
returnString = [returnString stringByAppendingString:@"alt='footer'"];
returnString = [returnString stringByAppendingString:@"align='middle' width='140' height='32' />"];
returnString = [returnString stringByAppendingString:@"</p></body></html>"];
[myWebView loadHTMLString:returnString baseURL:[NSURL URLWithString:@"http:www.google.com"]];

【问题讨论】:

    标签: iphone objective-c sdk


    【解决方案1】:
        NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
        NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];
    
        NSLog(@"webview %@", bundlePath);
    
    
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];  
        NSData *htmlData = [NSData dataWithContentsOfFile:filePath];  
        NSString * html =  [NSString stringWithContentsOfFile:filePath encoding:NSStringEncodingConversionAllowLossy error:nil];
        if (htmlData) {  
           [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:bundleBaseURL];  
        }
    

    使用过一次搜索功能:load-image-in-web-view-from-a-html-file

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多