In Missing Word, I need to get the exact bounds of the missing word and put a same-sized UITextField onto it.

Thanks to the power of TextKit which was introduced in iOS 7, this task can be accomplished pretty easily.

NSTextStorage *aStorage = textView.textStorage;
NSTextContainer *aContainer = textView.textContainer;
CGRect wordRect = [aManager boundingRectForGlyphRange:wordRange inTextContainer:aContainer];

// Don'f forget the inset
UIEdgeInsets inset = textView.textContainerInset;

wordRect.origin.y +=;
wordRect.origin.x += inset.left;

CGRect textFieldRect = [self.view convertRect:wordRect fromView:textView];

Why do I need the missing word’s exact bounds instead of the position?

If you use hint, you’ll notice the hint letters are not popping out from nowhere, they are appearing like part of the textField’s text.

Check out the letters inv in the above image. Actually, in is in the textView and v is in the textField.

One flaw, Misaligned Images

Turn on the Color Misaligned Images of the simulator, you’ll notice this:

The reason is that the “exact bounds” of the missing word look like this:

origin=(x=5, y=333.108) size=(width=58.378002, height=46.444)

These fractional parts will create a bit of blurriness of your text:

If you want the text to look sharp, you’ll need to use set the textFiled’s position pixel-aligned. But under that situation, the letter v looks one pixel lower:

Any ideas?

Missing Word is available on the app store. iTunes link