What is the best way to disable UITextField’s ‘return’ keyboard key if input area does not contain any text? UITextField with enablesReturnKeyAutomatically property set to YES enables return key even if there are only spaces entered, but I’d like it to enable return key only when the text is not empty. any suggestions?
What is the best way to disable UITextField’s ‘return’ keyboard key if input area
Share
I don’t know how you’d override the text input trait behaviour, but you could use the text field delegate method
textField:shouldChangeCharactersInRange:replacementString:to prevent the user being able to enter spaces into an otherwise blank string. This would prevent any whitespace text being added, so the return key should not be enabled.If you’re not bothered about the return key actually being enabled, you could use
textFieldShouldReturn:, again one of the text field delegate methods.