iOS NSAttributedString to HTML

后端 未结 3 1874
面向向阳花
面向向阳花 2020-12-13 10:08

I have an NSAttributed string (coming from HTML) that I set for a UITextView.

- (void)setHtml:(NSString *)html {

    NSData *html         


        
3条回答
  •  猫巷女王i
    2020-12-13 10:43

    I also had to convert a NSAtttributedString to HTML in one of my projects. The code for doing this is as follows

    //self.attributed String is the attributedString 
    NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
    NSData *htmlData = [self.attributedString dataFromRange:NSMakeRange(0, self.attributedString.length) documentAttributes:documentAttributes error:NULL];
    NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
    NSLog(@"%@", htmlString);
    

提交回复
热议问题