答案 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
}