如何从Swift中的段落开始UITextView

时间:2018-11-20 22:27:00

标签: swift uitextview

如何在UITextView中以一个很小的空格开始新行,我认为这是段落?

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要做的是使控制器面对UITextFieldDelegate

例如:

class ViewController: UIViewController,UITextFieldDelegate 
{
   //link the textfield
   @IBOutlet weak var textField: UITextField!

   override func viewDidLoad() 
   {
      super.viewDidLoad()
      // link the delegate to the textfield
      textField.delegate = self   
   }

    //this function detects the return button when it's pressed

   func textFieldShouldReturn(_ textField: UITextField) -> Bool 
   {
    //since we always want to start a new line with space we override the default function

     textField.text += "\n "
     return false
}