在 Mac OS X 中,有 AppKit 添加支持读写 NSAttributedString 为 RTF 格式。
在 iOS 中是否等效?我应该自己做吗?
最佳答案
您只想将字符串保存到磁盘吗?我会为此使用 NSCoding。
将对象写入文件:
result = [NSKeyedArchiver archiveRootObject:attributedString toFile:archivePath];
从文件中读取对象:
attributedString = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
您可以对任何符合“NSCoding”的对象执行此操作,并且很容易将对 NSCoding 的支持添加到您自己的类中。可以在以下位置找到更多信息:
关于ios - 在 iOS 中读/写 NSAttributedString 的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3724985/