转换NSAttributedString(使用具有图像的NSTextAttachment)到Html

时间:2016-06-07 09:12:41

标签: html ios objective-c nsattributedstring

这是我的代码:

UIImage *image = [UIImage imageNamed:@"recipient.png"];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = image;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString    alloc] initWithString:htmlString];

NSAttributedString *attstringImage = [NSAttributedString  attributedStringWithAttachment:textAttachment];

[attributedString appendAttributedString:attstringImage];

NSAttributedString *titleContent = (NSAttributedString *)attributedString;

NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute:   NSHTMLTextDocumentType};
NSData *htmlData = [titleContent dataFromRange:NSMakeRange(0, titleContent.length) documentAttributes:documentAttributes error:NULL];

NSString *html = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];

0 个答案:

没有答案