0
votes

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.

1
I didn't understood everything. Do you have some example and how you apply the effects? - Larme
@Larme My requirement is when i edit the content of the textview then after editing the content <ins> and <del> tag should appear for adding and deleting of any word respectively. That I can do by applying attributed styles but I need to post the edited content in html form as server needs this content in html format. - Praveen-K

1 Answers

0
votes
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];