3

I have a UITextField. While user is typing, I am using

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

to validate the string. And if the string is valid I want to enable the return key; if it is not valid I want to disable the return key. Is there a way to do this?

For example the return key would be disabled while the user types the characters in avai. Then the return would become enabled after the user finishes typing avail. Then the return would be disabled again as user types availabl; then become enabled again as user types available.

learner
  • 11,490
  • 26
  • 97
  • 169
  • Do you want to grey-out the return key on the displayed keyboard, or just to ignore the return key so the user has to continue editing? If the latter, use `textFieldShouldReturn` and return NO. – pbasdf Sep 08 '14 at 17:00
  • @pbasdf I want to gray out the key so user gets visual feedback. – learner Sep 08 '14 at 21:18
  • In which case, I think you will have to use a custom keyboard, though I've never done it myself. Check the docs for inputView and inputAccessoryView of UIResponder (which UITextField inherits). Sorry if that's old news... – pbasdf Sep 08 '14 at 21:29

0 Answers0