Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 255
Joshua J. McKinnon Avatar asked Oct 05 '09 01:10

Joshua J. McKinnon


1 Answers

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).

like image 130
mahboudz Avatar answered Sep 30 '22 04:09

mahboudz