Is there a way to programmatically enable or disable the Return Key on the UIKeyboard
? The closest I could find is enablesReturnKeyAutomatically
, but that only will tell whether to disable it at all.
Tap “123” key in the bottom-left corner of the keyboard. 2. The Return key is located in the bottom-right corner, next to the space bar.
Maybe the following code segment helps:
textfield.enablesReturnKeyAutomatically = YES;
This is publicly available in iPhone SDK in UITextInputTraits. Using this, return key will be disabled when no input text is available within text field.
You can override UITextField
's hasText
attribute to achieve this:
class CustomTextField : UITextField { override public var hasText: Bool { get { return evaluateString(text) } } }
Where evaluateString(_ text: String?) -> Bool
checks against your needed input criteria, for example character count.
Of course this does only work in combination with enablesReturnKeyAutomatically = true
set on the UITextField
.
I am aware that my answer is neither timely nor written in Objective-C, but given that I have not been able to find an answer anywhere else and this question being routinely referred to in other threads, I think that here is the best place to post it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With