link text box in Swift - swift

Is it possible to link text boxes in Swift? For example, I have two text boxes that the user can type in. When the user has filled up the first text box (--i.e. there's no more room for text) the cursor automatically moves to the second text box so any further characters typed will appear in the second text box.

You can use becomeFirstResponder method from the textfield:
//This textfield will get the focus.
yourNextTextField.becomeFirstResponder()
To check the number of letters in your UITextfield, you can implement the UITextFieldDelegate and use the shouldChangeCharactersInRange method.
In there you calculate the length of your string.

Related

TextView showing "?" mark instead of text using STM32 TouchGFX?

I want to fill a textView with a string, after a click on a button.
I did every thing correctly but it shows only the "a" character and the other with a fallback character.
this is the function that fill the text view buffer
The wildcard
The topography
You should use Unicode::strncpy() instead of snprintf()

Swift Text Field wrap to new line

I'm working on a swift project and have a Text Field. The user can input a string into this field. Currently if the user types too much then the string scrolls horizontally on the one line. How do I build a text field where once the first line is full it adds a line.
aaaaaaaaaaaaaaaaaaaaaaaaa
vs.
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaa
UITextField is one-line only.
You can replace your UITextField with UITextView in your storyboard. They are editable and selectable by default.

Setting focus in textfields

I have 3 textfields, which can hold at most one character. If a character is entered in first textfield, then the focus should automatically shift to the second and so on.
For this, I used textField:shouldChangeCharactersInRange:replacementString:
Going by this, I could check the length of my textfield and assign first responder status to the next textfield.
When i type a character in the first textfield, the character is displayed in the textfield, but the focus doesn't automatically shift to the next textfield. It shifts only when I enter the next alphabet, where it tries to check the condition, and thereby it fails, and then only the focus shifts to the next textfield.
IS there anyway where, the focus should be shifted to the second, just after the first character is entered.
Try checking the length of the replacementString parameter instead of that of the textfield
Call
- (BOOL)becomeFirstResponder
on it. You can check that it can become first responder with the method
- (BOOL)canBecomeFirstResponder

iOS UITextField formatted for time

I have a UITextField which I created programmatically. This text field is used to input a time. The placeholder text is "00:00:00.000". When the text field is tapped, a number pad will appear. Ideally, I want the gray place holder text to remain as the user types. As they enter a number, it replaces the gray zeros in the place holder text and skips over the colons and period (leaving the format intact without the user entering any punctuation). If it is not possible to keep the place holder text and replace it as the user types, I would like the punctuation to automatically be entered.
Thanks in advance!
iOS has a UIDatePicker control for this, if you want to go the way you are going then you will have handle all the user input your self.

How to figure out the current caret position in a UITextField?

I want to programmatically paste a string into a text field or text view at the current caret position.
Is there an easy way to do this? I would need to know the current caret position, but there's no method to retrieve it, right? Don't want to call private API. Is there any legal way to do it?
Use UITextView's selectedRange method. If the range has a non-zero length (in the case of the user having selected some text), just take the location (or NSMaxRange(), or replace the entire range...)
Instead of pasting option. Get the string from textfield or textview insert the string which you want to paste it by providing the index and then clear the textfield then pass the string which you inserted.