我有一个UITextView,它以注释文本的css样式显示内容。基本上,有一个htmlString有一些问题。
NSMutableAttributedString * attributedStringForComment = [[NSMutableAttributedString alloc] initWithData:[formatedStr dataUsingEncoding:NSUnicodeStringEncoding]选项:@ { NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
在UITextView上显示与css样式相同的内容。
现在,如果有人编辑文本,那么我们通过删除css样式来隐藏评论部分(因此用户无法删除其他评论)然后我们通过添加用于删除/的颜色的strike / color来应用NSMutableAttributedString的样式补充说。
问题: 当用户完成编辑部分时,我希望我的字符串编辑文本为带有注释的css样式的html。 当我们使用某种样式应用NSMutableAttributedString时,它会删除html标记和css样式。
任何技巧/提示都将帮助我找到解决方案。
答案 0 :(得分:0)
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];