Question

How do we implement selectionRectsForRange: from UITextInput Protocol ? Has anybody figured out this one? Is it just very dependent upon specific use-case needs? Or is there something in the frameworks that will call this method?

To silence the compiler it is of course appropriate to stub out the method, but will returning nil or an empty NSArray cause any harm?

Was it helpful?

Solution

According to session 220 at WWDC12 this method was added to support subclassing of UITextView where the implementation renders its own text. Sadly their sample code from that session isn't available, would love to peek at it to see if I've missed anything in my implementation.

It's fairly similar to how you'd implement -firstRectForRange: except you'd return all rects which covers the current selection.

Furthermore you'd have to subclass UITextSelectionRect (it's an abstract class like UITextPosition/UITextRange) which you'd return an array of from this method. Make sure to calculate the containsStart and containsEnd properties correctly and only return YES for one of each once across all the selection rects you return. These properties are used by UITextView to decide on where to place the selection resize "paddles".

Returning an empty array (or nil I suppose) would indicate that UITextView shouldn't draw any selection rects for the current selection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top