I'm implementing a custom UITextView (based on EGOTextView) using CoreText and conforming to the UITextInput
protocol. I have almost everything working fine (phew!), except for one annoying thing. Autocorrect suggestion text is mirrored vertically and its highlight is slightly shifted to the right. Here's what it looks like:
In the text field I typed "helo", which it autocorrects to "help." As you can see, the autocorrect text, but not its background, is vertically mirrored. Also, it's horiztontally offset to the right by ~7pt.
To address the second problem (the horizontal offset), I have verified that the firstRectForRange:
method returns the correct CGRect
. I've done this in two ways. The first was to visually check that when I display a UIMenuController
it shows up in the right spot (it does). The second is to draw an outline around the CGRect
returned by firstRectForRange:
. Here's the same text with the CGRect
outlined.
As you can see, the correct area is outlined, but the autocorrect is marked/highlighted incorrectly.
I'm happy to share any code, but it's a huge class and I'm pretty stumped now. Any pointers would be massively appreciated!
Edit: The source code is available on the Experimental branch of this repository: github.com/cbrauchli/EGOTextView.