我正在开发一个 iOS 应用程序,我需要在其中实现具有以下要求的基本文本视图:
- 富文本
- 字体强调(粗体、斜体)。
- 用于类似超链接的操作的内嵌图像。
- 滚动
- 文本选择
- 获取选定的文本字符范围。
- 如果需要,选择文本时滚动视图。
我相信我可以使用 UIWebView 来实现这一点,但问题是它提供的控制非常少,而且速度有点慢,并且在加载时显示空白屏幕。我想知道这是否可以通过核心文本来实现,但关于文本选择我不确定。我希望尽可能实现 iOS 原生行为。
我需要的与 Instapaper 的文本视图非常相似。
I'm working on an iOS app in which I need to implement a basic text view with these requirements:
- Rich text
- Font emphasis (bold, italics).
- Inline images for hyperlink-like actions.
- Scrolling
- Getting and setting the scroll offset (for remembering the previous scroll position).
- Text selection
- Getting the selected text character range.
- Scrolling the view when selecting text, if needed.
I believe I could achieve this with UIWebView
but the problem with this is that it provides very little control and is somewhat slow and shows a blank screen while loading. I was wondering if this could be achieved with Core Text but regarding the text selection I'm not sure. I'm hoping to achieve as iOS-native behaviour as possible.
What I'd need is pretty much like Instapaper's text view.
发布评论
评论(2)
OmniGroup 通过创建一个类似于
UITextView
的文本编辑器来完成类似的事情,它使用 Core Text 绘制文本,但也具有UITextView
的所有编辑功能以及富文本功能来自核心文本。您可以在此处找到它。
OmniGroup have done something like this by creating a text editor much like
UITextView
which draws the text using Core Text but also has all the editing features ofUITextView
as well as Rich text features from Core Text.You can find it here.
StackOverflow 中有一些关于此问题的答案,例如: 核心文本教程
然而,这是我读过的最好的教程关于 iOS 中的核心文本未在我找到的任何答案中列出: 如何创建带有核心文本的简单杂志应用
请注意,CoreText 仅适用于 iOS 3.2 或更高版本。
There are some answers about this in StackOverflow, for example: Core text tutorial
However the best tutorial I ever read about Core Text in iOS is not listed in any answer I've found: How to create a simple magazine app with core text
Please notice that CoreText is only available for iOS 3.2 or superior.