Search code examples
iosswiftuitextviewnewlinecarriage-return

Newline and / or Carriage Return in Swift String


I am attempting to add a Newline or Carriage return in a UITextView.

    var text = UITextField()
    text.text = "This is a text \r\n This is a text"

The result shows the entire text on one line:

This is a text This is a text

Is it not possible to do a Newline or CR in a UITextView? Or what am I missing here?


Solution

  • UITextField is generally single-line and does not support multiline text. Use a UITextView instead