Swift 字符串中的换行符和/或回车 Return

Newline and / or Carriage Return in Swift String

我正在尝试在 UITextView 中添加换行符或回车符 return。

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

结果在一行中显示了整个文本:

这是一篇文章这是一篇文章

无法在 UITextView 中进行换行或 CR 吗?或者我在这里缺少什么?

UITextField一般是单行,不支持多行文字。使用 UITextView 代替