开发者

How does one interact with a string drawn using UIStringDrawing/CoreText

开发者 https://www.devze.com 2023-01-09 23:11 出处:网络
I am attempting to work on an app that highlights certain key words. For this reason, I am looking at using either CoreText or UIStringDrawing to highlight these words (As in bold/underline/italicize/

I am attempting to work on an app that highlights certain key words. For this reason, I am looking at using either CoreText or UIStringDrawing to highlight these words (As in bold/underline/italicize/color) since UITextView doesn't seem to have these facilities (And I haven't had any luck with CATextLayer).

In either case I am able to successfully manipulate and draw the string. (I.E- I can find my important words in a string and apply the appropriate traits).

The problem I am having is that when text is drawn this way, it cannot be interacted with directly. Seeing as the user will be able to delete/add text to the text view i开发者_JAVA技巧n question, this is an important thing to have.

At the moment I have stuck my drawing routines into the drawRect: method of a UITextView subclass (Mostly just to see that I can do what I want). Does UITextView have a different method that can be overridden so that it uses my code to render its string? If not, how might I go about doing what I've described?

For an example of what I am talking about, look at how the Notes app finds and highlights phone numbers and addresses. I'm not looking for phone numbers or addresses, but it gets the point across.


After a bit of additional reading, it seems that you need to subclass/override a LOT of methods in order to create your own text view whose text you can draw. Apple's docs touch on it, but they don't go much into detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消