I\'ve searched everywhere and can\'t seem to find a clear answer on updating a label in real-time.
How do i go about updating a UILabel
(real-time) with
step 1:Extend class to UITextFieldDelegate
class ViewController: UIViewController,UITextFieldDelegate
In ViewDidLoad()
Step 2: Add Following code into ViewDidLoad()
txtDemo.delegate = self
txtDemo.addTarget(self, action: #selector(LabelChanged(_:)), for:.editingChanged)
step 3: Make new Function as below:
func LabelChanged(_ sender:Any) {
lblDemo.text = txtDemo.text
}
Or Also use delegate method:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
lblDemo.text = txtDemo.text
return true
}
Here lblDemo is UILabel outlet and txtDemo is UITextField outlet