Alex1987
Alex1987

Reputation: 9457

Emulating UITextView text rendering with CoreText?

I'm attempting to create a TextView with the ability to highlight various words. I don't want to use the attributedText property in iOS 6 because I want to support iOS 5 and because of other issues (see here for example: UITextView attributedText and syntax highlighting).

So the only option I've got is to use CoreText. I found this project: https://github.com/KayK/RegexHighlightView. What it basically does is overrides the drawRect method of the UITextView and draws the contents with CoreText. The problem is that the Core Text rendering is different from UITextView rendering - which leads the cursor to be in a wrong place (gets worse as the text gets longer).

Is there any hope to fix this issue? Maybe some other clever approach?

Upvotes: 0

Views: 663

Answers (2)

uchuugaka
uchuugaka

Reputation: 12782

Try EGOTextView. Or you can do the webView way. (UITextView actually does this under the hood mostly)

Upvotes: 0

Aleksei Belezeko
Aleksei Belezeko

Reputation: 90

Try this: https://github.com/mattt/TTTAttributedLabel TTTAttributedLabel supports iOS 4.0 and higher.

Upvotes: 1

Related Questions