track user input from UIKeyboard - iphone

How can I get user input of the UIKeyboard on the iPhone?
I want to track, if the user hits "backspace" when the firstResponder UITextField is empty.
I know how I can track a text change but if the field is empty the text don't change when hit "backspace".

You can put a single space character as the default textfield text. If it tries to disappear in your textshouldchange delegate then the user hit a backspace. You can remove the leading space before actually using the text result.

Related

How to disable text input for a label but still have it as a button

The Text Fields that Say 100 are the ones i'm referring to.
I have Text Fields that I don't want to be editable until a later point so I turned off User Interaction. However, I still want them to function as a button to go to another view. Is there anyway to turn off text input but still keep it as a button?

Selecting all text in a UITextField when an user has VoiceOver enabled

In my App I have several text fields which a user can edit. If the text field already contains text and the user begins to edit the text field, I want to highlight all text, so it's easier for the user to delete the content of the field.
Searching the web I have found the solution to set the text fields delegate to self and use the function didBeginEditing(). In this function I just call textField.selectAll(nil). As long as I don't use VoiceOver on the phone this works well. As soon as you turn VoiceOver on the text in a textField doesn't get highlighted when beginning to edit the text field. The function didBeginEditing though is still called. I checked this with a simple print statement.
Has anyone an idea why this isn't working? Is there maybe another way to highlight all text in a text field?
Thank you for every answer!
The selection of text is lost when the VoiceOver selects the element. You should select the text after the VoiceOver focus on element.
On didBeginEditing you can check if
UIAccessibility.isVoiceOverRunning and then you select the text after one second.
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
self.textField.selectAll(nil)
}
Not the best solution, but it's working. Also, for a person with vision problem I don't think is useful to select all the text, eventually you should inform the user that the text is selected.

Detect back space for secure text field. Delegate method for detecting backspace key

Possible duplicate Detect backspace in UITextField
I am having 5 secure password text field which accepts 1 character each. When you enter 1 character in a text field then the next textfield becomes first responder. The problem occurs when i press "BACK SPACE" button.
My requirement is : When i press back button in an empty text field, it should detect the backspace button press and cursor should navigate to the previous text field and previous text field becomes first responder.
What is happening is when i press the back button in an empty text field, the back space is not detected and it stays in the same empty text field.
As suggested in this link Detect backspace in UITextField i have tried putting zero width space character \u200B white editing did begin but it takes it as character and becomes visible in text field. Any help is highly appreciated.
The following link have a solution from Jacob Caraballo which helped me solve my problem,
Detect backspace in UITextField

Custom Pin Password Boxes on iOS

I want to create a 4 character custom password entry like the iPhone lock screen page. It's going to have a custom designed keyboard pinpad, but thats not the question. I have 4 boxes for the entry of the pin, and each box is separated and has its own custom design. I currently have a clear UITextView on top of each box. However, I'm not really sure how to link all these together so that when I enter a number in the first box, it automatically advances to the next box so I can type the next number. After the last number has been entered, it should automatically check to see if the password is correct and if so do some action. What is the best way to do this?
When implementing UITextFieldDelegate you should check on textField:shouldChangeCharactersInRange:replacementString:
and you can move keyboard focus to next UITextField via BecomeFirstResponder documentation
So on last UITextField you will hide keyboard and disable all UITextboxes automatically, but If I were you, I would prefer to provide button to start checking pin (to let user correct pin if mistyped)

UITextField Keep the placeholder text on while focused

I want to keep the place holder text shown while it is focused (that is, while it is the first responder). It should stay that way only until something is typed and the field no longer blank.
Address Book app's Search bar behaves like this, as do the new contact entry fields.
Is there any way to do that?
I don't think this comes "built in" for you to activate it, but you can build it rather easily on your own: Create a UILabel you want to display and when the focus is set onto the TextField place the UILabel at the right spot (slightly after the cursor).
As soon as the user enters a character you hide the UILabel. You can see when the user starts the edit and starts to type by adding your class as delegate to the UISearchBar (see callbacks "searchBar:textDidChange:" and "searchBarTextDidBeginEditing:"): http://bit.ly/eQlvRz