Search code examples
iosobjective-ciphonecocoa-touchuitextfield

Can I set the insertion point on a UITextField


I have a UITextField that I want to present to the user with a pre-filled suffix. Obviously, I'd like to have the insertion point set to the beginning of the pre-filled text.

It doesn't seem obvious to me how to do this (e.g., there's no insertionPoint property), but is there a tricky way to get this done?


Solution

  • Override drawTextInRect: to always draw your suffix, even though it is not contained in the UITextFields text (use a temp string that takes the textfield.text, appends your suffix, and draws it). Once the user is done editing, then append your suffix to the string (or use them separately if it helps).