It is not a difficult task to achieve.
I will present that the problem with this approach is coherence. Remember that your users use their fingers, not styles. The finger has a large surface area, and getting into the exact area of ββthe pixels is quite difficult, especially with small text. I suggest playing not in the simulator, where you have an exact pointing device, but on the device.
The first task is to disable the default behavior or UITextView . This is not a difficult task - you can βattackβ the problem at the touchesBegan:withEvent: level, where you will need to understand what it is about (single tap against panning or long press) or the gesture recognizer level, where you disable text-type private gesture recognizers, which specifically handle the movement of the cursor in case of pressing (compared to other types of touch). I did the latter for different projects, and it is possible. You can also try the approach without disabling the default behavior, but then the cursor may flicker. Try and decide.
Now to achieve what you need. Get the touch point somehow (using the UIResponder API or gesture recognizer). Remember that a text view is a scroll view that includes a large view in which the content is embedded. You must convert this touch point from the text view coordinate system to the internal view coordinate system using the convertPoint: API. After that, you can use the text view layout manager to get the index of the character at the touch point:
NSUInteger chIdx = [self characterIndexForPoint:touchPoint inTextContainer:self.textContainer fractionOfDistanceBetweenInsertionPoints:NULL];
This index can be used to position the text view cursor using the selectedRange property.
source share