HTML from NSAttributedString

后端 未结 2 1153
礼貌的吻别
礼貌的吻别 2021-02-04 11:08

Rather than converting HTML to an attributed string, I need to convert it back to HTML. This can easily be done on Mac as can be seen here: http://www.justria.com/2011/01/18/how

2条回答
  •  日久生厌
    2021-02-04 12:11

    Use the below code. it works well.

    NSAttributedString *s = ...;
    NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute:    NSHTMLTextDocumentType};    
    NSData *htmlData = [s dataFromRange:NSMakeRange(0, s.length)    documentAttributes:documentAttributes error:NULL];
    NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
    

提交回复
热议问题