Custom UIView with keyboard input?
I have a custom UILabel subclass to display currency values. I want the user to be able to enter numbers and allow the forms to represent those numbers in currency - like a cash register. This makes UITextField an unacceptable choice for such input.
I've already overridden hitTest: so that the UILabel will return by itself - this appears to be an error. Also, I have overridden both canBecomeFirstResponder and startFirstResponder to return YES. However, none of these methods are called.
I only want the user to enter numbers and use the backspace key. I have implemented UITextInputTraits but the keyboard does not appear. So, can this be done? And if so, what am I missing?
source to share
I did something like this. Subclass UITextField, clear the text color and paste over it to display the formatted version.
edit - in fact, strictly speaking, you don't even need to subclass it. Just implement the delegate method (-textField: shouldChangeCharactersInRange: replacementString :), add the label to the UITextField and format the label text, but you need to.
source to share