像文字处理器一样格式化文本的 iPhone 应用程序

发布于 2024-11-26 18:00:52 字数 381 浏览 2 评论 0原文

很抱歉提出这样的一般性问题,但我想知道是否(以及如何)可以编写一个 iPhone 应用程序,在不同页面上格式化 txt 文件 - 就像 Microsoft Word 在布局模式下打开一个新文档时所做的那样,并且粘贴一个txt文件。

换句话说,我不想使用无休止的 UITextView。我所需要的只是一个可以格式化不同页面上的文本的编辑器。

有没有简单的方法或者我需要自己编写所有程序?即,将txt文件切成不同的部分并相应地处理用户输入(例如,如果他粘贴某些内容,如果他删除某些内容,如果他到达页面末尾,等等)。

我想这在 Mac OS X 上是相当微不足道的(我刚刚看了他们关于如何创建一个简单的文本编辑器的文档),但我感觉这在 iPhone 上几乎是不可能的。

任何想法将不胜感激!

Sorry for such a general questions, but I'm wondering if (and how) it is possible to write an iPhone App which formats a txt file on different pages - just like Microsoft Word would do in layout mode if you open a new document and paste a txt file.

In other words, I don't want to use an UITextView which is endless. All I need is an editor which formats text on different pages.

Is there an easy way or would I need to program everything by myself? I.e. cut txt files in different pieces and handle the user input accordingly (e.g. if he pastes something, if he deletes something, if he reaches the end of the page, etc. etc.).

I guess this would be quite trivial on Mac OS X (I just had a look at their docs of how to create a simple text editor) but I get the feeling that this is nearly impossible on the iPhone.

Any thoughts would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心凉 2024-12-03 18:00:53

将一个大文本拆分成看起来像 Ms Word 中的布局视图的内容不是问题。当您考虑编辑文本时,问题就会出现。您可以采取的一种方法是始终将完整的 tekst 保留在一个占位符中,并允许用户编辑该占位符而不是特定的“页面”。然后,编辑完成后,将文本拆分为适当的页面。如果您想单独编辑每个页面,则必须自己处理页面调整,这很痛苦,但也是可能的。

It's not a problem to split one large text into something that looks like a layout view in Ms Word. The problem appears when you consider editing the text. One way you can go about it is to always keep full tekst in one placeholder and allow user to edit that placeholder instead of particular "pages". Then after the edit is finished you split the text into appropriate pages. If you would want to edit each page separately you would have to handle adjustment of pages yourself which is a pain, but possible.

不甘平庸 2024-12-03 18:00:53

对于显示,您可以使用 -[NSString sizeWithFont:forWidth:lineBreakMode:] 来测量文本。从那里,您需要手动将文本分割成适合页面大小的块。

如果文本是可编辑的,那么您还需要实现 UITextInput 协议,并且可能应该使用 Core Text 来进行文本绘制。这可以概括为:分配工作。

For display you can use -[NSString sizeWithFont:forWidth:lineBreakMode:] to measure your text. From there you need to manually split the text into chunks that fit your page size.

If the text is to be editable, then you need to also implement the UITextInput protocol, and should probably use Core Text to do your text drawing. This can be summed up as: allot of work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文