Reputation: 3401
I have a UITextView, which display the content with css style for comment text. Basically, there is a htmlString with somestyles.
NSMutableAttributedString *attributedStringForComment = [[NSMutableAttributedString alloc] initWithData:[formatedStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
Which display the content as with css style on UITextView.
Now, if some one edit the text, then we hide the comment section by removing the css styles(so user can not delete the other's comment) then we apply the style with NSMutableAttributedString by adding attribute for strike/color for deleting/added word.
Problem : When user is done with editing part I want my string with editing text as html with comment's css style. When we apply NSMutableAttributedString with some style, it removes the html tag and css style.
Any trick/tips will help me to reach the solution.
Upvotes: 0
Views: 114
Reputation: 17
NSAttributedString *yourHTMLSourceCodeString = textView.attributedText;
NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [yourHTMLSourceCodeString dataFromRange:NSMakeRange(0, yourHTMLSourceCodeString.length) documentAttributes:documentAttributes error:NULL];
NSString* body = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
Upvotes: 0