Three way to create customized input control for UITextField
Posted in :
Recently I need to create some customized textfield to input numbers and text on iPad. I don’t like the default keyboard on iPad because it takes too much of the screen, and in some cases covers up the input field.
1) From iphonedevsdk: What is proper way to do UITextField text change call back? (this also mentioned by stackoverflow)
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventTouchDown];
The downside of this approach is: it takes a press (a tap and hold) to trigger the event.
2) InputView
Create a customized view such as this one at raywenderlich, then set the inputView of textfield. I used this approach to create a number pad that used to only input numbers. There is some limit to this approach as well: the location of customized input view is usually fixed, and in my case (a double picker) for text field (table cell), that is not ideal. I was using pop over controller (again raywenderlich), combined with approach 1, the user does not like the “hold”. After I changed to approach 2, the user does not like the fixed location of input view. So I did more research, and eventually I found the following approach that works for me.
One tip: make sure lock the input view, otherwise it will mess up things after iPad rotation.
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
3) self delegate, UITextFieldDelegate
Make sure do this in viewDidLoad (or other place initialize the text field):
myTextField.delegate = self;
This way I could have both “single tap” and the pop over controller.