ios - 在 iOS 中读/写 NSAttributedString 的简单方法?

标签 ios rtf

在 Mac OS X 中,有 AppKit 添加支持读写 NSAttributedString 为 RTF 格式。

在 iOS 中是否等效?我应该自己做吗?

最佳答案

您只想将字符串保存到磁盘吗?我会为此使用 NSCoding。

将对象写入文件:

result = [NSKeyedArchiver archiveRootObject:attributedString toFile:archivePath];

从文件中读取对象:

attributedString = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];

您可以对任何符合“NSCoding”的对象执行此操作,并且很容易将对 NSCoding 的支持添加到您自己的类中。可以在以下位置找到更多信息:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html%23//apple_ref/doc/uid/10000047-SW1

关于ios - 在 iOS 中读/写 NSAttributedString 的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3724985/

相关文章:

ios - 我如何在Apple Developer Site上注册公司?

iOS UIScrollView setScrollEnabled 失败

ios - 如何使我的 ios 应用程序对 wifi 更改事件使用react

ios - 以编程方式更改另一个类中的数组

r - 如何使用 R 将 rtf 字符串转换为纯文本?

iphone - iOS 中的多语言文档 (RTF) : Files, SQLite、核心数据?如何?

ios - Swift:无法使用类型为 'init' 的参数列表调用 '($t3, NSString)'

applescript - 使用 AppleScript 将 .rtf 文本复制到电子邮件正文中

c# - RichTextBox 控件的 Windows 窗体 RTF 格式

replace - Coldfusion Replace() 不适用于 MS-Word 文档的所有页面