RTF 到带表的 NSAttributedString (iOS)
RTF to NSAttributedString with Tables (iOS)
我在 iOS 应用程序中使用 RTF 文件作为模板。其中一部分是一对 table;但是,在从 RTF 转换为 NSAttributedString 时,table 会丢失。如果我将它们作为普通标签发送,则格式有效。但是,由于 table 中每个单元格中的大部分文本都是多行的,制表符不起作用。
有没有办法从 NSAttributedString 中的 RTF 转换 tables 或直接在 NSAttributedString 中创建 tables?
因此,在 HTML 或 RTF 的 iOS 的 NSAttributedString 上没有发现对 tables 的真正支持,我的解决方案是在 HTML 中构建页面,将它们加载到 UIWebView 中,而不是将 NSAttributedString 加载到 UITextView 中。通过这种方式,我得到了我想要的 table 格式,而且更好的是,我有一个视图可以用于创建文档的 PDF。
func getText()
{
do {
let attibutedString = try NSAttributedString(url: rtfdFileUrl!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.rtfd], documentAttributes: nil)
textView.attributedText = attibutedString
} catch {
print(error.localizedDescription)
}
}
这个我试过了,但是是rtfd的,你可以试试rtf。它工作正常并且 table 是正确的,但是如果我试图编辑 table 中的文本它会中断。如果你只需要显示 table 就可以了。
我在 iOS 应用程序中使用 RTF 文件作为模板。其中一部分是一对 table;但是,在从 RTF 转换为 NSAttributedString 时,table 会丢失。如果我将它们作为普通标签发送,则格式有效。但是,由于 table 中每个单元格中的大部分文本都是多行的,制表符不起作用。
有没有办法从 NSAttributedString 中的 RTF 转换 tables 或直接在 NSAttributedString 中创建 tables?
因此,在 HTML 或 RTF 的 iOS 的 NSAttributedString 上没有发现对 tables 的真正支持,我的解决方案是在 HTML 中构建页面,将它们加载到 UIWebView 中,而不是将 NSAttributedString 加载到 UITextView 中。通过这种方式,我得到了我想要的 table 格式,而且更好的是,我有一个视图可以用于创建文档的 PDF。
func getText()
{
do {
let attibutedString = try NSAttributedString(url: rtfdFileUrl!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.rtfd], documentAttributes: nil)
textView.attributedText = attibutedString
} catch {
print(error.localizedDescription)
}
}
这个我试过了,但是是rtfd的,你可以试试rtf。它工作正常并且 table 是正确的,但是如果我试图编辑 table 中的文本它会中断。如果你只需要显示 table 就可以了。