Swift Text Field wrap to new line - swift

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.

Related

Make most recently entered text in UITextField visible when not editing

With a Swift UITextField the default behavior when not editing is to ellipse the most recently entered text if the text is too long to fit in the space allowed for the text field. As shown in this image:
When you begin to edit the text field, the text shifts left to make the most recently entered text visible. As shown in this image:
How can I achieve this effect when I am not editing the text field? I would like the most recently viewed text to always be visible no matter whether or not the user is currently editing the text field. If the text is too long for the space provided for the text field, it should not display the oldest text.
This could be easily achieved using UITextView if that suits other requirements:
let textView = UITextView()
textView.textContainer.maximumNumberOfLines = 1
textView.textContainer.lineBreakMode = .byTruncatingHead

link text box in 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.

How to set a UITextField to edit severals lines?

I have a UITextField that is 300px width and 270px height. When I want to edit it, the cursor goes automatically in the middle and I can only write on the middle line.
How can I set this UITextField to have severals lines and a cursor starting at the top-left ?
Simple answer, just use UITextView instead.
UITextfield is designed for single line only, If you want to enter multi line text than use UITextView instead and set its editable property to YES than it would behave like textfield!
[myTextView setEditable:YES];
Note: You can also set it via Interface Builder, select the "editable" box & It will be multiline by default.

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 format different characters in a UILabel's string differently?

I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
Use a UIWebView and render the text as HTML.
I ended up using the textRectForBounds:limitedToNumberOfLines: to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.