iphone - 将图像添加到 HTML 字符串 iphone

标签 iphone ios objective-c

<分区>

我如何将我的 Xcode 项目中存在的图像添加到 HTML 字符串中以打印输出。

我已经尝试了以下代码,但图像没有打印出来,而是 PDF 中出现了一个空白框。

-(NSString *)prepareHTMLText {
    NSMutableString *body = [NSMutableString stringWithString:@"<!DOCTYPE html><html><body>"];


        [body appendString:@"<h2>Ingredients</h2>"];

     [body appendFormat:@"<p>%@ %@</p>", @"text", @"TEStText"];

   // [body appendFormat:@"<img src=\"%@\" alt=\"\" height=\"100\" width=\"100\"/>",[[NSBundle mainBundle] pathForResource:@"edit" ofType:@"png"]];

    [body appendFormat:@"<img src=\"%@\"/>",[UIImage imageNamed:@"edit.png"]];

    [body appendString:@"</body></html>"];
    return body;
}

我正在按照上面的方式输出 enter image description here

最佳答案

您需要一个 URL,而不是文件路径或图像对象本身。尝试类似的东西:

NSString *fileURLString = [[[NSBundle mainBundle] URLForResource:@"edit" withExtension:@"png"] absoluteString];
[body appendFormat:@"<img src=\"%@\"/>", fileURLString];

关于iphone - 将图像添加到 HTML 字符串 iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14438039/

相关文章:

iphone - NSXMLParser 找到特定元素的 CDATA

iphone - 如何让 Qemu USB Passthrough 为 iPad/iPhone 工作?

iphone - 如何在 iPhone 上使用陀螺仪 z 轴?

iphone - 我怎样才能用 AVPlayer 播放 pcm

objective-c - 如何将单例类设置为委托(delegate)?

ios - 如何使用iOS-GTLYouTube库播放YouTube视频?

iphone - 无法使用 UIScrollView 和 pagingEnabled=YES 禁用弹跳

objective-c - 尝试在表中插入值时数据库被锁定?

iphone - 如何在 iPhone 中实现 Facebook 集成的社交框架?

iphone - 图像旋转到左侧90度电子邮件附件iPhone