如何将图像设置为uiwebview?

时间:2014-10-30 12:00:02

标签: ios iphone xcode webview

enter image description here

我创建了一个html代码,如上所示,代码已上传到http://www.ged.Ic.com网站。

在Xcode项目中添加了图像名称“1.jpg”。

从webview打开iPad应用加载http://www.ged.Ic.com/page/时。

如何将图像从Xcode项目设置为 img src =“来自xcode的图像路径”

2 个答案:

答案 0 :(得分:1)

NSString *imageFileName = @"image";
NSString *imageFileExtension = @"png";

NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];

NSString *imgHTMLTag = [NSString stringWithFormat:@"<img src=\"file://%@\" />", imagePath];

答案 1 :(得分:0)

NSString *imageUrlString = @"http://www.gstatic.com/translate/intl/ru/logo.png";
NSString *yourText = @"Some text here";

NSString *htmlString = [NSString stringWithFormat:@"<img src='%@'/><br><b>%@</b>", imageUrlString, yourText];    
[myWebView loadHTMLString:htmlString baseURL:nil];