问题
I know how to convert the common NSAttributedString
(which has no image) into HTML. I set the Images as NSTextAttachment
to NSAttributedString
. How could I convert the whole attributed string into HTML?
UIImage *image = [UIImage imageNamed:@"Test.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];
Please suggest me with quick answer
来源:https://stackoverflow.com/questions/37605862/convert-nsattributedstring-with-nstextattachment-having-image-to-html-in-ios-o