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

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.

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?

GWT:how to display a popup at the poistion of the key pressed

I am trying to display a word suggestion list when ctl+space entered as in eclipse.
For that I need to know the location where user has entered ctrl+space so that i can display the suggestion list exact below to the word user just entered.
I see ways to get the mouse cursor position , But isnt there a way to get the keyboard button pressed position ,
I am writing inside textArea, I tried getCursor, but it gives me the no of word on which user entered ctrl+space. Not the location as per the Window.
Any idea
thanks
There is no reliable, accurate and cross-browser way to do it with TextArea.
You can experiment with a RichTextArea (you don't have to provide a toolbar for rich text features) and its getFormatter().insertHTML() method. It will insert a new HTML element at a cursor position. You can insert a list of suggested words, that you can style to look anyway you like, or you can insert an empty div and try to show a panel relative to it.
Or you can use a different UI approach. Create a panel with a fixed position relative to your TextArea and show your suggested words there - similar to the way good smartphone keyboards show suggested words just above the keyboard itself. Once your users realize that suggested words always show up in the same place, they may even like this design better.

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

custom keyboard - how to dispatch event which signals the UITextField to update the text accordingaly

I am trying to create a custom keypad through a collection of buttons, which function like a regular keypad provided in iphone.
Now series of action that should occur
-text field is selected
-user presses the button
-text field is designated as first responder
-something like key event is launched so that text field is updated according to the character associated with the button.
If above supposition of flow is correct, please guide me how to get around the last step. I am newbie to iphone, so please let me know if am missing any of the basic.
Found an other way which did the needed by simulating the behaviour of keyEvent( which i doubt if exist in iphone sdk).
Basic outline of the procedure is like
-push the content to pasteboard
-call the paste function on UITextField
so when button is pressed, content corresponding to the button is copied to pasteboard and then paste function is called on the UITextField, so that the content get inserted into it.
Detailed description of steps can be found here:
http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html