convert NSAttributedstring (with NSTextAttachment having image) to html in ios obj c

我的未来我决定 提交于 2020-01-14 05:44:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!