首页 > 解决方案 > textfield to a label atumatically?

问题描述

Is there any way in which I can send information from a textfield to a label automatically while writing for example if I have 2 texfield and 1 label one by name and the other by last name that when writing a single letter or a name this automatically appears in the label
some way to do this with de button

-> @IBAction func bt(_ sender: Any) { text =texfield!.text text = txfield!.text text.text = "\(textt!) \(texxt!)"

标签: swiftlabeltextfield

解决方案


您可以在 View Controller 的 viewDidLoad 方法中添加此文本更改侦听器。

yourTextField.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), for: .editingChanged)

并将此功能添加到您的视图控制器

@objc func textFieldDidChange(_ textField: UITextField) {
     yourLabel.text = textField.text
}

推荐阅读