Enable Return Key in empty UITextView - ios

In my app, I need to enable Return Key on UITextView even if UITextView is empty. By default, return key is disabled, before user not entered any symbols.
How I can do this?
Thanks.

I need to enable Return Key on UITextView even if UITextView is empty.
Actually, the return key is enabled by default no matter the text view is empty or not. However, if you want to set the return key to disabled by default, you need to set the enablesReturnKeyAutomatically to YES. As the Apple Doc said:
The default value for this property is NO. If you set it to YES, the keyboard disables the return key when the text entry area contains no text. As soon as the user enters any text, the return key is automatically enabled.

Related

Handle accessibility when user click on empty area

General scenario: When user clicks on empty area, control does not goto any other place.
My scenario: When user clicks on empty area, control goes to last cell.
Is there any way to handle the empty area click?
I have already manages accessibilityElements array which comprises of needed UI elements only.
I have kept the isAccessibilityElement false to elements which are not needed
This is occuring on one screen only. I researched about it but no solution found yet.
You can override the accessibilityActivate() of empty area.
Return true if you wish to modify the default implementation i.e., write your custom code for what needs to be done and then return true.
If you don't want to change the default implementation i e., let the OS decide what happens on double tap of empty area, return false. By default, return type is false.
Read more here
https://developer.apple.com/documentation/objectivec/nsobject/1615165-accessibilityactivate

Disabling enter button in iOS keyboard

I have an iOS keyboard question.
Say we have a UITextField (let's call it textfield) and a standard virtual keyboard, with the Enter key set to Send. We'd like to disable the Send key when UITextField is empty, otherwise enable it. We have set enablesReturnKeyAutomatically to YES on the text field. This works fine when we manually edit the text in the text field.
However, the Send key doesn't seem to work fine when we programmatically change the text. Our app will clear the text field by calling textfield.text = #"" once the Send key is hit and the text is sent. In this case, we expect the Send key to be disabled since textfield's content is empty. But no -- it appears enabled.
We want to disable the Send key in such a case. Please share your experience if possible.
Thanks!
I think the best you can do is to ignore the return event this way:
- (BOOL) textFieldShouldReturn:(UITextField*) textField {
return textField.text.length > 0;
}

Dynamically change keyboard's return button but preserve type

I have an input field the user needs to fill with an alphanumeric code. The keyboard the user uses to type the code has a dynamic return button that changes to "send" as he writes some text on the field. When the field is empty the return button has the default value.
To dynamically change the return button type I use the following code:
if([textField.text isEqualToString:#""])
{
textField.returnKeyType = UIReturnKeyDefault;
}
else
{
textField.returnKeyType = UIReturnKeySend;
}
[textField reloadInputViews];
However this has the following drawback: since the code is alphanumeric, the user may be typing numbers, and yet the keyboard will always switch back to the letter keyboard, so to type more than one number in a row he will need to be continuously switching to number keyboard.
Is there any way to dynamically change the return key of a keyboard as the user types but to preserve the keyboard state to letters or numbers keyboard?
I think this is not a bug on Apple's side, more a missing implementation of API for the keyboard. With the new iOS8 API you might want to create your own keyboard returning the UIKeyboardType.
For iOS7 I worked around by inspecting the views of the keyboard. Use the US2KeyboardType CocoaPod or the source:
https://github.com/ustwo/US2KeyboardType
As Martin noted above, it's not a bug on Apple's side, but on my side. However I'll be posting the solution I've found since it is the one that solves that particular problem:
Instead of manually changing the return key type when there is text on the text field, Apple provides us with a property called enablesReturnKeyAutomatically that when set to YES it automatically manages the issue, enabling and disabling the return key depending on whether there is text or not in the text field.
Therefore you don't need to modify the returnKeyType property, and thus, no calling to reloadInputViews is required, so the keyboard doesn't change back to its original state.

UITextField clearsOnInsertion does not working

I set
textField.clearsOnInsertion=YES
but nothing happened. I am using XCode 5.0 and iOS 7.0
You should firstly make it clear what is clearsOnInsertion. See Apple's doc:
clearsOnInsertion
A Boolean value indicating whether inserting text
replaces the previous contents.
Discussion
The default value of this property is NO. When the value of
this property is YES and the text view is in editing mode, the
selection UI is hidden and inserting new text clears the contents of
the text view and sets the value of this property back to NO.
clearsOnInsertion is very useless in my opinion. See the screenshot:
The text field is in editing mode and the keyboard is shown but the selection UI is hidden. When you input any thing, it will replace the old text. That's it.
Another related useful property is clearsOnBeginEditing
clearsOnBeginEditing
A Boolean value indicating whether the text field removes old text when editing begins.
Try this:
textField.clearsOnBeginEditing = YES;
if you want to clear previous text when editing begins you should use
textfield.clearsOnBeginEditing = YES

changing keyboard return key label text

Iphone's onscreen keyboard has a number of predefined labels for its return key: done, return, go, google, etc. In my case I just want it to say Save, but it's not in the list. How can I create my own?
You can't. UIKeyboard is read-only.

Resources