I have a UITextField and I'm taking some input which are dollars in this care. I need to implement how to always be present the '$' sign after I'm typing the numbers (I mean the '$' to the right (not to the left) of my cursor because I will be writing the code for the Euro (€) sign as well). Any ideas?
You can use UITextField delegate or listen the notification, like UITextFieldTextDidChangeNotification
.
In these method, check the text and add '$'.
Since '$' should be at the correct position, I suggest use UITextField property selectedTextRange
to calculate the position, and After that use setSelectedTextRange
to move the cursor to the correct place.
UITextPosition * tp = [self.passwordTextField positionFromPosition:self.passwordTextField.beginningOfDocument offset:self.passwordTextField.text.length - @"$".length];
UITextRange *sr = [self.passwordTextField textRangeFromPosition:tp toPosition:tp];
I think the sr
is the selectedTextRange's value.