Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UItextField with Multiple lines

I am trying to make a form and the requirement is to have a UItextfield with multiple lines which means, when a specific number of characters are entered in one line the blip moves to next line also on hitting enter it should enter the next line as well.

Currently, I am working with Xcode 9.4 but it offers a single line text field.

like image 741
Mayank Wadhwa Avatar asked Sep 13 '25 22:09

Mayank Wadhwa


2 Answers

I used UITextView with this code:

lazy var commentTextView: UITextView = {
    // Create a TextView.
    let textView: UITextView = UITextView()

    // Round the corners.
    textView.layer.masksToBounds = true

    // Set the size of the roundness.
    textView.layer.cornerRadius = 20.0

    // Set the thickness of the border.
    textView.layer.borderWidth = 1

    // Set the border color to black.
    textView.layer.borderColor = UIColor.systemGray.cgColor

    // Set the font.
    textView.font = UIFont.systemFont(ofSize: 16.0)

    // Set font color.
    textView.textColor = UIColor.black

    // Set left justified.
    textView.textAlignment = NSTextAlignment.left

    // Automatically detect links, dates, etc. and convert them to links.
    textView.dataDetectorTypes = UIDataDetectorTypes.all

    // Set shadow darkness.
    textView.layer.shadowOpacity = 0.5

    // Make text uneditable.
    textView.isEditable = true

    return textView
}()

and this is the result

enter image description here

like image 121
Jorge Casariego Avatar answered Sep 16 '25 11:09

Jorge Casariego


You should use UITextView for multiline string or there is third party library which you can use. MultilineTextField

like image 36
Sanoj Kashyap Avatar answered Sep 16 '25 13:09

Sanoj Kashyap